protected function TypedDataCommands::formatOutput in Typed Data API enhancements 8
Helper function to format command output.
2 calls to TypedDataCommands::formatOutput()
- TypedDataCommands::listDataFilters in src/
Commands/ TypedDataCommands.php - Show a list of available TypedDataFilter plugins.
- TypedDataCommands::listFormWidgets in src/
Commands/ TypedDataCommands.php - Show a list of available TypedDataFormWidget plugins.
File
- src/
Commands/ TypedDataCommands.php, line 90
Class
- TypedDataCommands
- Drush 9+ commands for the Typed Data API Enhancements module.
Namespace
Drupal\typed_data\CommandsCode
protected function formatOutput($plugin_manager_service, $title, $categories = TRUE, $short = FALSE) {
// @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);
}
}