function RulesCommands::formatOutput

Helper function to format command output.

4 calls to RulesCommands::formatOutput()
RulesCommands::listActions in src/Commands/RulesCommands.php
Show a list of Rules actions.
RulesCommands::listConditions in src/Commands/RulesCommands.php
Show a list of Rules conditions.
RulesCommands::listEvents in src/Commands/RulesCommands.php
Show a list of Rules events.
RulesCommands::listExpressions in src/Commands/RulesCommands.php
Show a list of Rules expressions.

File

src/Commands/RulesCommands.php, line 385

Class

RulesCommands
Drush 9+ commands for the Rules module.

Namespace

Drupal\rules\Commands

Code

protected function formatOutput($plugin_manager_service, $title, $categories = TRUE, $short = FALSE) {
    // Dependency injection deliberately not used because we don't know
    // a priori what service will be needed. So ignore the phpcs message.
    // @phpcs:ignore DrupalPractice.Objects.GlobalDrupal.GlobalDrupal
    $definitions = \Drupal::service($plugin_manager_service)->getDefinitions();
    $plugins = [];
    foreach ($definitions as $plugin) {
        if ($categories) {
            if ($short) {
                $plugins[(string) $plugin['category']][] = $plugin['id'];
            }
            else {
                $plugins[(string) $plugin['category']][] = $plugin['label'] . '   (' . $plugin['id'] . ')';
            }
        }
        else {
            if ($short) {
                $plugins[] = $plugin['id'];
            }
            else {
                $plugins[] = $plugin['label'] . '   (' . $plugin['id'] . ')';
            }
        }
    }
    $this->output()
        ->writeln(dt($title));
    if ($categories) {
        ksort($plugins);
        foreach ($plugins as $category => $plugin_list) {
            $this->output()
                ->writeln('  ' . $category);
            sort($plugin_list);
            $this->output()
                ->writeln('    ' . implode(PHP_EOL . '    ', $plugin_list));
            $this->output()
                ->writeln('');
        }
    }
    else {
        $unique = array_unique($plugins);
        sort($unique);
        $this->output()
            ->writeln('  ' . implode(PHP_EOL . '  ', $unique) . PHP_EOL);
    }
}