theme = $theme; // Determine the namespaces to search for. $namespaces = []; foreach ($theme->getAncestry() as $ancestor) { $namespaces['Drupal\\' . $ancestor->getName()] = [DRUPAL_ROOT . '/' . $ancestor->getPath() . '/src']; } $this->namespaces = new \ArrayObject($namespaces); $this->subdir = $subdir; $this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name; $this->pluginInterface = $plugin_interface; $this->themeHandler = \Drupal::service('theme_handler'); $this->themeManager = \Drupal::service('theme.manager'); } /** * {@inheritdoc} */ protected function alterDefinitions(&$definitions) { if ($this->alterHook) { $this->themeManager->alter($this->alterHook, $definitions); } } /** * {@inheritdoc} */ public function createInstance($plugin_id, array $configuration = array()) { if (!isset($configuration['theme'])) { $configuration['theme'] = $this->theme; } return parent::createInstance($plugin_id, $configuration); } /** * Retrieves the cache tags used to invalidate caches. * * @return array * An indexed array of cache tags. */ public function getCacheTags() { return [Bootstrap::CACHE_TAG]; } /** * {@inheritdoc} */ public function getDefinitions($sorted = TRUE) { $definitions = parent::getDefinitions(); if ($sorted) { uasort($definitions, ['\Drupal\Component\Utility\SortArray', 'sortByWeightElement']); } return $definitions; } /** * Retrieves all definitions where the plugin ID matches a certain criteria. * * @param string $regex * The regex pattern to match. * * @return array[] * An array of plugin definitions (empty array if no definitions were * found). Keys are plugin IDs. */ public function getDefinitionsLike($regex) { $definitions = []; foreach ($this->getDefinitions() as $plugin_id => $definition) { if (preg_match($regex, $plugin_id)) { $definitions[$plugin_id] = $definition; } } ksort($definitions, SORT_NATURAL); return $definitions; } /** * {@inheritdoc} */ protected function providerExists($provider) { return $this->themeHandler->themeExists($provider); } }