Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function rebuildThemeData()
 {
     $listing = $this->getExtensionDiscovery();
     $themes = $listing->scan('theme');
     $engines = $listing->scan('theme_engine');
     $extension_config = $this->configFactory->get('core.extension');
     $installed = $extension_config->get('theme') ?: array();
     // Set defaults for theme info.
     $defaults = array('engine' => 'twig', 'regions' => array('sidebar_first' => 'Left sidebar', 'sidebar_second' => 'Right sidebar', 'content' => 'Content', 'header' => 'Header', 'primary_menu' => 'Primary menu', 'secondary_menu' => 'Secondary menu', 'footer' => 'Footer', 'highlighted' => 'Highlighted', 'messages' => 'Messages', 'help' => 'Help', 'page_top' => 'Page top', 'page_bottom' => 'Page bottom', 'breadcrumb' => 'Breadcrumb'), 'description' => '', 'features' => $this->defaultFeatures, 'screenshot' => 'screenshot.png', 'php' => DRUPAL_MINIMUM_PHP, 'libraries' => array());
     $sub_themes = array();
     $files = array();
     // Read info files for each theme.
     foreach ($themes as $key => $theme) {
         // @todo Remove all code that relies on the $status property.
         $theme->status = (int) isset($installed[$key]);
         $theme->info = $this->infoParser->parse($theme->getPathname()) + $defaults;
         // Add the info file modification time, so it becomes available for
         // contributed modules to use for ordering theme lists.
         $theme->info['mtime'] = $theme->getMTime();
         // Invoke hook_system_info_alter() to give installed modules a chance to
         // modify the data in the .info.yml files if necessary.
         // @todo Remove $type argument, obsolete with $theme->getType().
         $type = 'theme';
         $this->moduleHandler->alter('system_info', $theme->info, $theme, $type);
         if (!empty($theme->info['base theme'])) {
             $sub_themes[] = $key;
             // Add the base theme as a proper dependency.
             $themes[$key]->info['dependencies'][] = $themes[$key]->info['base theme'];
         }
         // Defaults to 'twig' (see $defaults above).
         $engine = $theme->info['engine'];
         if (isset($engines[$engine])) {
             $theme->owner = $engines[$engine]->getExtensionPathname();
             $theme->prefix = $engines[$engine]->getName();
         }
         // Prefix screenshot with theme path.
         if (!empty($theme->info['screenshot'])) {
             $theme->info['screenshot'] = $theme->getPath() . '/' . $theme->info['screenshot'];
         }
         $files[$key] = $theme->getPathname();
     }
     // Build dependencies.
     // @todo Move into a generic ExtensionHandler base class.
     // @see https://drupal.org/node/2208429
     $themes = $this->moduleHandler->buildModuleDependencies($themes);
     // Store filenames to allow system_list() and drupal_get_filename() to
     // retrieve them without having to scan the filesystem.
     $this->state->set('system.theme.files', $files);
     // After establishing the full list of available themes, fill in data for
     // sub-themes.
     foreach ($sub_themes as $key) {
         $sub_theme = $themes[$key];
         // The $base_themes property is optional; only set for sub themes.
         // @see ThemeHandlerInterface::listInfo()
         $sub_theme->base_themes = $this->getBaseThemes($themes, $key);
         // empty() cannot be used here, since ThemeHandler::doGetBaseThemes() adds
         // the key of a base theme with a value of NULL in case it is not found,
         // in order to prevent needless iterations.
         if (!current($sub_theme->base_themes)) {
             continue;
         }
         // Determine the root base theme.
         $root_key = key($sub_theme->base_themes);
         // Build the list of sub-themes for each of the theme's base themes.
         foreach (array_keys($sub_theme->base_themes) as $base_theme) {
             $themes[$base_theme]->sub_themes[$key] = $sub_theme->info['name'];
         }
         // Add the theme engine info from the root base theme.
         if (isset($themes[$root_key]->owner)) {
             $sub_theme->info['engine'] = $themes[$root_key]->info['engine'];
             $sub_theme->owner = $themes[$root_key]->owner;
             $sub_theme->prefix = $themes[$root_key]->prefix;
         }
     }
     return $themes;
 }