You are here

protected function KeyConfigOverrideAddForm::getConfigNames in Key 8

Get the configuration names for a specified configuration type.

Parameters

string|null $config_type: The configuration type.

Return value

array The configuration names.

1 call to KeyConfigOverrideAddForm::getConfigNames()
KeyConfigOverrideAddForm::buildForm in src/Form/KeyConfigOverrideAddForm.php
Form constructor.

File

src/Form/KeyConfigOverrideAddForm.php, line 289

Class

KeyConfigOverrideAddForm
KeyConfigOverrideAddForm class.

Namespace

Drupal\key\Form

Code

protected function getConfigNames($config_type = NULL) {
  $names = [
    '' => $this
      ->t('- Select -'),
  ];

  // Handle entity configuration types.
  if ($config_type && $config_type !== 'system.simple') {
    $entity_storage = $this->entityTypeManager
      ->getStorage($config_type);
    foreach ($entity_storage
      ->loadMultiple() as $entity) {
      $entity_id = $entity
        ->id();
      if ($label = $entity
        ->label()) {
        $names[$entity_id] = new TranslatableMarkup('@label (@id)', [
          '@label' => $label,
          '@id' => $entity_id,
        ]);
      }
      else {
        $names[$entity_id] = $entity_id;
      }
    }
  }
  elseif ($config_type == 'system.simple') {

    // Gather the configuration entity prefixes.
    $config_prefixes = array_map(function (EntityTypeInterface $definition) {
      return $definition
        ->getConfigPrefix() . '.';
    }, $this
      ->getConfigEntityTypeDefinitions(TRUE));

    // Get all configuration names.
    $names = $this->configStorage
      ->listAll();
    $names = array_combine($names, $names);

    // Filter out any names that match a configuration entity prefix.
    foreach ($names as $config_name) {
      foreach ($config_prefixes as $config_prefix) {
        if (strpos($config_name, $config_prefix) === 0) {
          unset($names[$config_name]);
        }
      }
    }
  }
  return $names;
}