You are here

function drush_config_import_names in Config Importer and Tools 8.0

Same name and namespace in other branches
  1. 8.2 config_import.drush.inc \drush_config_import_names()
  2. 8 config_import.drush.inc \drush_config_import_names()

Implements drush_COMMAND().

File

./config_import.drush.inc, line 96
Drush integration.

Code

function drush_config_import_names() {
  try {
    $entity_manager = Drupal::entityTypeManager();
    $options = _drush_config_import_get_options();
    $rows = [];

    // Handle simple configuration.
    if ('system.simple' === $options['type']) {
      $config_prefixes = [];
      $headers = [
        'Name',
      ];
      foreach ($entity_manager
        ->getDefinitions() as $entity_type => $definition) {
        if ($definition instanceof ConfigEntityTypeInterface) {
          $config_prefixes[] = $definition
            ->getConfigPrefix() . '.';
        }
      }
      foreach (Drupal::service('config.storage')
        ->listAll() as $config_name) {
        foreach ($config_prefixes as $config_prefix) {
          if (strpos($config_name, $config_prefix) !== FALSE) {
            $rows[] = [
              $config_name,
            ];
          }
        }
      }
    }
    else {
      $headers = [
        'Name',
        'Label',
      ];
      foreach ($entity_manager
        ->getStorage($options['type'])
        ->loadMultiple() as $entity_id => $entity) {
        $rows[] = [
          $entity_id,
          $entity
            ->label() ?: $entity_id,
        ];
      }
    }
    _config_import_print_table($rows, $headers);
  } catch (Exception $e) {
    drush_log($e
      ->getMessage(), 'error');
  }
}