listInfo example

    $this->moduleHandler->invokeAll('themes_installed', [$themes_installed]);

    return !empty($themes_installed);
  }

  /** * {@inheritdoc} */
  public function uninstall(array $theme_list) {
    $extension_config = $this->configFactory->getEditable('core.extension');
    $theme_config = $this->configFactory->getEditable('system.theme');
    $list = $this->themeHandler->listInfo();
    foreach ($theme_list as $key) {
      if (!isset($list[$key])) {
        throw new UnknownExtensionException("Unknown theme: $key.");
      }
      if ($key === $theme_config->get('default')) {
        throw new \InvalidArgumentException("The current default theme $key cannot be uninstalled.");
      }
      if ($key === $theme_config->get('admin')) {
        throw new \InvalidArgumentException("The current administration theme $key cannot be uninstalled.");
      }
      // Base themes cannot be uninstalled if sub themes are installed, and if
$this->assertFalse(\Drupal::moduleHandler()->moduleExists('automated_cron'), 'Automated cron module uninstalled during import.');
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('options'), 'Options module uninstalled during import.');
    $this->assertFalse(\Drupal::moduleHandler()->moduleExists('text'), 'Text module uninstalled during import.');

    // Ensure installations and uninstallation occur as expected.     $installed = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_installed', []);
    $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
    $expected = ['options', 'text', 'ban', 'automated_cron'];
    $this->assertSame($expected$uninstalled, 'Options, Text, Ban and Automated Cron modules uninstalled in the correct order.');
    $this->assertEmpty($installed, 'No modules installed during import');

    $theme_info = \Drupal::service('theme_handler')->listInfo();
    $this->assertFalse(isset($theme_info['olivero']), 'Olivero theme uninstalled during import.');

    // Verify that the automated_cron.settings configuration object was only     // deleted once during the import process.     $delete_called = \Drupal::state()->get('ConfigImportUITest.automated_cron.settings.delete', 0);
    $this->assertSame(1, $delete_called, "The automated_cron.settings configuration was deleted once during configuration import.");
  }

  /** * Tests concurrent importing of configuration. */
  
return ['views.settings'];
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form$form_state);

    $config = $this->config('views.settings');
    $options = [];
    foreach ($this->themeHandler->listInfo() as $name => $theme) {
      if ($theme->status) {
        $options[$name] = $theme->info['name'];
      }
    }

    // This is not currently a fieldset but we may want it to be later,     // so this will make it easier to change if we do.     $form['basic'] = [];

    $form['basic']['ui_show_default_display'] = [
      '#type' => 'checkbox',
      
      // are not removed, because the list of search directories is only       // compiled once in this constructor. The current code only works due to       // coincidence: The request that installs (for instance, a new theme)       // does not instantiate this plugin manager at the beginning of the       // request; when routes are being rebuilt at the end of the request,       // this service only happens to get instantiated with the updated list       // of installed themes.       $directories = [];
      foreach ($this->moduleHandler->getModuleList() as $name => $module) {
        $directories[$name] = $module->getPath();
      }
      foreach ($this->themeHandler->listInfo() as $theme) {
        $directories[$theme->getName()] = $theme->getPath();
      }

      // Check for files named MODULE.config_translation.yml and       // THEME.config_translation.yml in module/theme roots.       $this->discovery = new YamlDiscovery('config_translation', $directories);
      $this->discovery = new InfoHookDecorator($this->discovery, 'config_translation_info');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
    }
    return $this->discovery;
  }

  
/** * Indicates whether the theme is accessible based on whether it is installed. * * @param string $theme * The name of a theme. * * @return bool * TRUE if the theme is installed, FALSE otherwise. */
  public function checkAccess($theme) {
    $themes = $this->themeHandler->listInfo();
    return !empty($themes[$theme]->status);
  }

}

  protected $themes = [];

  /** * {@inheritdoc} */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeHandlerInterface $theme_handler) {
    parent::__construct($entity_type$storage);
    $this->themes = $theme_handler->listInfo();
  }

  /** * {@inheritdoc} */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static(
      $entity_type,
      $container->get('entity_type.manager')->getStorage($entity_type->id()),
      $container->get('theme_handler')
    );
  }

  public static function create(ContainerInterface $container$base_plugin_id) {
    return new static(
      $container->get('theme_handler')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
      if ($this->themeHandler->hasUi($theme_name)) {
        $this->derivatives[$theme_name] = $base_plugin_definition;
        $this->derivatives[$theme_name]['title'] = $theme->info['name'];
        $this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
      }
    }
    return $this->derivatives;
  }

}

  public function getWarning() {
    $themes = [];
    $default_theme = $this->configFactory->get('system.theme')->get('default');
    if (!empty($default_theme)) {
      $themes[$default_theme] = $this->themeHandler->listInfo()[$default_theme]->info;
    }

    $admin_theme = $this->configFactory->get('system.theme')->get('admin');
    if (!empty($admin_theme) && $admin_theme !== $default_theme) {
      $themes[$admin_theme] = $this->themeHandler->listInfo()[$admin_theme]->info;
    }

    // Collect information on which themes/base themes have ckeditor_stylesheets     // configuration, but do not have corresponding ckeditor5-stylesheets     // configuration.     $ckeditor_stylesheets_use = [];
    
return $active_theme;
  }

  /** * {@inheritdoc} */
  public function getActiveThemeByName($theme_name) {
    if ($cached = $this->cache->get('theme.active_theme.' . $theme_name)) {
      return $cached->data;
    }
    $themes = $this->themeHandler->listInfo();

    // If no theme could be negotiated, or if the negotiated theme is not within     // the list of installed themes, fall back to the default theme output of     // core and modules (like Stark, but without a theme extension at all). This     // is possible, because loadActiveTheme() always loads the Twig theme     // engine. This is desired, because missing or malformed theme configuration     // should not leave the application in a broken state. By falling back to     // default output, the user is able to reconfigure the theme through the UI.     // Lastly, tests are expected to operate with no theme by default, so as to     // only assert the original theme output of modules (unless a test manually     // installs a specific theme).

  public function __construct($paths, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, array $twig_config = []) {
    parent::__construct($paths);

    // Add namespaced paths for modules and themes.     $namespaces = [];
    foreach ($module_handler->getModuleList() as $name => $extension) {
      $namespaces[$name] = $extension->getPath();
    }
    foreach ($theme_handler->listInfo() as $name => $extension) {
      $namespaces[$name] = $extension->getPath();
    }

    foreach ($namespaces as $name => $path) {
      $this->addPath($path . '/templates', $name);
      // Allow accessing the root of an extension by using the namespace without       // using directory traversal from the `/templates` directory.       $this->addPath($path$name);
    }
    if (!empty($twig_config['allowed_file_extensions'])) {
      // Provide a safe fallback for sites that have not updated their

  public function uninstall(Request $request) {
    $theme = $request->query->get('theme');
    $config = $this->config('system.theme');

    if (isset($theme)) {
      // Get current list of themes.       $themes = $this->themeHandler->listInfo();

      // Check if the specified theme is one recognized by the system.       if (!empty($themes[$theme])) {
        // Do not uninstall the default or admin theme.         if ($theme === $config->get('default') || $theme === $config->get('admin')) {
          $this->messenger()->addError($this->t('%theme is the default theme and cannot be uninstalled.', ['%theme' => $themes[$theme]->info['name']]));
        }
        else {
          $this->themeInstaller->uninstall([$theme]);
          $this->messenger()->addStatus($this->t('The %theme theme has been uninstalled.', ['%theme' => $themes[$theme]->info['name']]));
        }
      }

function hook_rebuild() {
  $themes = \Drupal::service('theme_handler')->listInfo();
  foreach ($themes as $theme) {
    _block_rehash($theme->getName());
  }
}

/** * Alter the configuration synchronization steps. * * @param array $sync_steps * A one-dimensional array of \Drupal\Core\Config\ConfigImporter method names * or callables that are invoked to complete the import, in the order that * they will be processed. Each callable item defined in $sync_steps should * either be a global function or a public static method. The callable should * accept a $context array by reference. For example: * @code * function _additional_configuration_step(&$context) { * // Do stuff. * // If finished set $context['finished'] = 1. * } * @endcode * For more information on creating batches, see the * @link batch Batch operations @endlink documentation. * * @see callback_batch_operation() * @see \Drupal\Core\Config\ConfigImporter::initialize() */
// Theme settings.     if ($theme = $entity->getTheme()) {
      $form['theme'] = [
        '#type' => 'value',
        '#value' => $theme,
      ];
    }
    else {
      $theme = $this->config('system.theme')->get('default');
      $theme_options = [];
      foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) {
        if (!empty($theme_info->status)) {
          $theme_options[$theme_name] = $theme_info->info['name'];
        }
      }
      $form['theme'] = [
        '#type' => 'select',
        '#options' => $theme_options,
        '#title' => $this->t('Theme'),
        '#default_value' => $theme,
        '#ajax' => [
          'callback' => '::themeSwitch',
          
/** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['theme'] = [
      '#type' => 'select',
      '#title' => $this->t('Theme'),
      '#default_value' => $this->configuration['theme'],
      '#options' => array_map(function D$theme_info) {
        return $theme_info->info['name'];
      }$this->themeHandler->listInfo()),
    ];
    return parent::buildConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['theme'] = $form_state->getValue('theme');
    parent::submitConfigurationForm($form$form_state);
  }

  
protected function setUp(): void {
    parent::setUp();
    $this->installConfig(['system']);
  }

  /** * Verifies that no themes are installed by default. */
  public function testEmpty() {
    $this->assertEmpty($this->extensionConfig()->get('theme'));

    $this->assertEmpty(array_keys($this->themeHandler()->listInfo()));
    $this->assertEmpty(array_keys(\Drupal::service('theme_handler')->listInfo()));

    // Rebuilding available themes should always yield results though.     $this->assertNotEmpty($this->themeHandler()->rebuildThemeData()['stark'], 'ThemeHandler::rebuildThemeData() yields all available themes.');

    // theme_get_setting() should return global default theme settings.     $this->assertTrue(theme_get_setting('features.favicon'));
  }

  /** * Tests installing a theme. */
Home | Imprint | This part of the site doesn't use cookies.