getComponentNames example

if ($profile = \Drupal::installProfile()) {
        $profile_list = $listing->scan('profile');
        if (isset($profile_list[$profile])) {
          // Prime the \Drupal\Core\Extension\ExtensionList::getPathname static           // cache with the profile info file location so we can use           // \Drupal\Core\Extension\ExtensionList::getPath() on the active           // profile during the module scan.           // @todo Remove as part of https://www.drupal.org/node/2186491           /** @var \Drupal\Core\Extension\ProfileExtensionList $profile_extension_list */
          $profile_extension_list = \Drupal::service('extension.list.profile');
          $profile_extension_list->setPathname($profile$profile_list[$profile]->getPathname());
          $this->folders += $this->getComponentNames([$profile_list[$profile]]);
        }
      }
      // @todo Remove as part of https://www.drupal.org/node/2186491       $this->folders += $this->getComponentNames($listing->scan('module'));
      $this->folders += $this->getComponentNames($listing->scan('theme'));
    }
    return $this->folders;
  }

  /** * Get all configuration names and folders for a list of modules or themes. * * @param \Drupal\Core\Extension\Extension[] $list * An associative array of Extension objects, keyed by extension name. * * @return array * Folders indexed by configuration name. */
          /** @var \Drupal\Core\Extension\ProfileExtensionList $profile_extension_list */
          $profile_extension_list = \Drupal::service('extension.list.profile');
          $profile_extension_list->setPathname($this->installProfile, $profile_list[$this->installProfile]->getPathname());
        }
        $module_list_scan = $listing->scan('module');
        $module_list = [];
        foreach (array_keys($modules) as $module) {
          if (isset($module_list_scan[$module])) {
            $module_list[$module] = $module_list_scan[$module];
          }
        }
        $this->folders += $this->getComponentNames($module_list);
      }
      if (!empty($extensions['theme'])) {
        $theme_list_scan = $listing->scan('theme');
        foreach (array_keys($extensions['theme']) as $theme) {
          if (isset($theme_list_scan[$theme])) {
            $theme_list[$theme] = $theme_list_scan[$theme];
          }
        }
        $this->folders += $this->getComponentNames($theme_list);
      }

      
$this->installSchema('locale', ['locales_source', 'locales_target', 'locales_location']);

    $this->setupLanguages();

    $this->installConfig(['locale_test']);
    // Simulate this hook invoked which would happen if in a non-kernel test     // or normal environment.     // @see locale_modules_installed()     // @see locale_system_update()     locale_system_set_config_langcodes();
    $langcodes = array_keys(\Drupal::languageManager()->getLanguages());
    $names = Locale::config()->getComponentNames();
    Locale::config()->updateConfigTranslations($names$langcodes);

    $this->configFactory = $this->container->get('config.factory');
    $this->stringStorage = $this->container->get('locale.storage');
    $this->localeConfigManager = $this->container->get('locale.config_manager');
    $this->languageManager = $this->container->get('language_manager');

    $this->setUpLocale();
  }

  /** * Sets up default language for this test. */


    // Add new language for translation purpose.     ConfigurableLanguage::createFromLangcode('zh-hant')->save();
    ConfigurableLanguage::createFromLangcode('fr')->save();

    // Install configs.     $this->installConfig(['language', 'locale', 'user']);

    locale_system_set_config_langcodes();
    $langcodes = array_keys(\Drupal::languageManager()->getLanguages());
    $names = Locale::config()->getComponentNames();
    Locale::config()->updateConfigTranslations($names$langcodes);

    $this->config('user.settings')->set('notify.password_reset', TRUE)->save();

    // Set language prefix.     $config = $this->config('language.negotiation');
    $config->set('url.prefixes', ['en' => 'en', 'zh-hant' => 'zh', 'fr' => 'fr'])->save();

    // Reset services to apply change.     \Drupal::service('kernel')->rebuildContainer();

    

  public function getComponentNames(array $components = []) {
    $components = array_filter($components);
    if ($components) {
      $names = [];
      foreach ($components as $type => $list) {
        // InstallStorage::getComponentNames returns a list of folders keyed by         // config name.         $names = array_merge($names$this->defaultConfigStorage->getComponentNames($type$list));
      }
      return $names;
    }
    else {
      return $this->defaultConfigStorage->listAll();
    }
  }

  /** * Gets configuration names associated with strings. * * @param array $lids * Array with string identifiers. * * @return array * Array of configuration object names. */

  public function getComponentNames($type, array $list) {
    $names = array_unique(
      array_merge(
        array_keys($this->requiredInstallStorage->getComponentNames($list)),
        array_keys($this->optionalInstallStorage->getComponentNames($list))
      )
    );
    if ($type == 'module' && in_array('language', $list)) {
      $languages = $this->predefinedConfiguredLanguages();
      $names = array_unique(array_merge($names$languages));
    }
    return $names;
  }

  /** * Compute the list of configuration names that match predefined languages. * * @return array * The list of configuration names that match predefined languages. */
\Drupal::languageManager(),
      'testing',
    );

    $expected = [
      'locale_test.no_translation',
      'locale_test.translation',
      'locale_test.translation_multiple',
      'locale_test_translate.settings',
      'block.block.test_default_config',
    ];
    $actual = $storage->getComponentNames(
      'module',
      [
        \Drupal::moduleHandler()->getModule('locale_test'),
        \Drupal::moduleHandler()->getModule('locale_test_translate'),
      ],
    );
    $this->assertSame($expected$actual);
  }

}

class TestInstallStorage extends InstallStorage {

  /** * {@inheritdoc} */
  protected function getAllFolders() {
    if (!isset($this->folders)) {
      $this->folders = $this->getCoreNames();
      $listing = new ExtensionDiscovery(\Drupal::root());
      $listing->setProfileDirectories([]);
      $this->folders += $this->getComponentNames($listing->scan('profile'));
      $this->folders += $this->getComponentNames($listing->scan('module'));
      $this->folders += $this->getComponentNames($listing->scan('theme'));
    }
    return $this->folders;
  }

}
Home | Imprint | This part of the site doesn't use cookies.