/** * {@inheritdoc} */ public function listExtensionConfig(Extension $extension) { $extension_config = []; foreach ($this->extensionStorages as $directory => $extension_storage) { $extension_config = array_merge($extension_config, array_keys($extension_storage->getComponentNames([$extension->getName() => $extension]))); } return $extension_config; }
/** * @param $fullPath * @return string */ public function getPath($fullPath = false) { if ($fullPath) { return $this->root . '/' . parent::getPath(); } return parent::getPath(); }
/** * Alter the information parsed from module and theme .info.yml files * * This hook is invoked in _system_rebuild_module_data() and in * \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData(). A module * may implement this hook in order to add to or alter the data generated by * reading the .info.yml file with \Drupal\Core\Extension\InfoParser. * * @param array $info * The .info.yml file contents, passed by reference so that it can be altered. * @param \Drupal\Core\Extension\Extension $file * Full information about the module or theme. * @param string $type * Either 'module' or 'theme', depending on the type of .info.yml file that * was passed. */ function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $file, $type) { // Only fill this in if the .info.yml file does not define a 'datestamp'. if (empty($info['datestamp'])) { $info['datestamp'] = $file->getMTime(); } }
/** * {@inheritdoc} */ public function getActiveTheme(Extension $theme, array $base_themes = []) { $theme_path = $theme->getPath(); $values['path'] = $theme_path; $values['name'] = $theme->getName(); // Prepare stylesheets from this theme as well as all ancestor themes. // We work it this way so that we can have child themes override parent // theme stylesheets easily. $values['stylesheets'] = array(); // CSS file basenames to override, pointing to the final, overridden filepath. $values['stylesheets_override'] = array(); // CSS file basenames to remove. $values['stylesheets_remove'] = array(); // Grab stylesheets from base theme. $final_stylesheets = array(); foreach ($base_themes as $base) { if (!empty($base->stylesheets)) { foreach ($base->stylesheets as $media => $stylesheets) { foreach ($stylesheets as $name => $stylesheet) { $final_stylesheets[$media][$name] = $stylesheet; } } } $base_theme_path = $base->getPath(); if (!empty($base->info['stylesheets-remove'])) { foreach ($base->info['stylesheets-remove'] as $basename) { $values['stylesheets_remove'][$basename] = $base_theme_path . '/' . $basename; } } if (!empty($base->info['stylesheets-override'])) { foreach ($base->info['stylesheets-override'] as $name) { $basename = drupal_basename($name); $values['stylesheets_override'][$basename] = $base_theme_path . '/' . $name; } } } // Add stylesheets used by this theme. if (!empty($theme->stylesheets)) { foreach ($theme->stylesheets as $media => $stylesheets) { foreach ($stylesheets as $name => $stylesheet) { $final_stylesheets[$media][$name] = $stylesheet; } } } if (!empty($theme->info['stylesheets-remove'])) { foreach ($theme->info['stylesheets-remove'] as $basename) { $values['stylesheets_remove'][$basename] = $theme_path . '/' . $basename; if (isset($values['stylesheets_override'][$basename])) { unset($values['stylesheets_override'][$basename]); } } } if (!empty($theme->info['stylesheets-override'])) { foreach ($theme->info['stylesheets-override'] as $name) { $basename = drupal_basename($name); $values['stylesheets_override'][$basename] = $theme_path . '/' . $name; if (isset($values['stylesheets_remove'][$basename])) { unset($values['stylesheets_remove'][$basename]); } } } // And now add the stylesheets properly. $values['stylesheets'] = $final_stylesheets; // Do basically the same as the above for libraries $values['libraries'] = array(); // Grab libraries from base theme foreach ($base_themes as $base) { if (!empty($base->libraries)) { foreach ($base->libraries as $library) { $values['libraries'][] = $library; } } } // Add libraries used by this theme. if (!empty($theme->libraries)) { foreach ($theme->libraries as $library) { $values['libraries'][] = $library; } } $values['engine'] = isset($theme->engine) ? $theme->engine : NULL; $values['owner'] = isset($theme->owner) ? $theme->owner : NULL; $values['extension'] = $theme; $base_active_themes = array(); foreach ($base_themes as $base_theme) { $base_active_themes[$base_theme->getName()] = $this->getActiveTheme($base_theme, array_slice($base_themes, 1)); } $values['base_themes'] = $base_active_themes; return new ActiveTheme($values); }
/** * Get folder inside each component that contains the files. * * @param \Drupal\Core\Extension\Extension $extension * The Extension object for the component. * * @return string * The configuration folder name for this component. */ protected function getComponentFolder(Extension $extension) { return $extension->getPath() . '/' . $this->getCollectionDirectory(); }
/** * Builds a table row for the system modules page. * * @param array $modules * The list existing modules. * @param \Drupal\Core\Extension\Extension $module * The module for which to build the form row. * @param $distribution * * @return array * The form row for the given module. */ protected function buildRow(array $modules, Extension $module, $distribution) { // Set the basic properties. $row['#required'] = array(); $row['#requires'] = array(); $row['#required_by'] = array(); $row['name']['#markup'] = $module->info['name']; $row['description']['#markup'] = $this->t($module->info['description']); $row['version']['#markup'] = $module->info['version']; // Generate link for module's help page, if there is one. $row['links']['help'] = array(); if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) { if ($this->moduleHandler->invoke($module->getName(), 'help', array('help.page.' . $module->getName(), $this->routeMatch))) { $row['links']['help'] = array('#type' => 'link', '#title' => $this->t('Help'), '#url' => Url::fromRoute('help.page', ['name' => $module->getName()]), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help')))); } } // Generate link for module's permission, if the user has access to it. $row['links']['permissions'] = array(); if ($module->status && \Drupal::currentUser()->hasPermission('administer permissions') && in_array($module->getName(), $this->moduleHandler->getImplementations('permission'))) { $row['links']['permissions'] = array('#type' => 'link', '#title' => $this->t('Permissions'), '#url' => Url::fromRoute('user.admin_permissions'), '#options' => array('fragment' => 'module-' . $module->getName(), 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => $this->t('Configure permissions')))); } // Generate link for module's configuration page, if it has one. $row['links']['configure'] = array(); if ($module->status && isset($module->info['configure'])) { $route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array(); if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) { $links = $this->menuLinkManager->loadLinksByRoute($module->info['configure']); /** @var \Drupal\Core\Menu\MenuLinkInterface $link */ $link = reset($links); // Most configure links have a corresponding menu link, though some just // have a route. if ($link) { $description = $link->getDescription(); } else { $request = new Request(); $request->attributes->set('_route_name', $module->info['configure']); $route_object = $this->routeProvider->getRouteByName($module->info['configure']); $request->attributes->set('_route', $route_object); $request->attributes->add($route_parameters); $description = $this->titleResolver->getTitle($request, $route_object); } $row['links']['configure'] = array('#type' => 'link', '#title' => $this->t('Configure'), '#url' => Url::fromRoute($module->info['configure'], $route_parameters), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-configure'), 'title' => $description))); } } // Present a checkbox for installing and indicating the status of a module. $row['enable'] = array('#type' => 'checkbox', '#title' => $this->t('Install'), '#default_value' => (bool) $module->status, '#disabled' => (bool) $module->status); // Disable the checkbox for required modules. if (!empty($module->info['required'])) { // Used when displaying modules that are required by the installation profile $row['enable']['#disabled'] = TRUE; $row['#required_by'][] = $distribution . (!empty($module->info['explanation']) ? ' (' . $module->info['explanation'] . ')' : ''); } // Check the compatibilities. $compatible = TRUE; // Initialize an empty array of reasons why the module is incompatible. Add // each reason as a separate element of the array. $reasons = array(); // Check the core compatibility. if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) { $compatible = FALSE; $reasons[] = $this->t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => \Drupal::CORE_COMPATIBILITY)); } // Ensure this module is compatible with the currently installed version of PHP. if (version_compare(phpversion(), $module->info['php']) < 0) { $compatible = FALSE; $required = $module->info['php'] . (substr_count($module->info['php'], '.') < 2 ? '.*' : ''); $reasons[] = $this->t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $required, '!php_version' => phpversion())); } // If this module is not compatible, disable the checkbox. if (!$compatible) { $status = implode(' ', $reasons); $row['enable']['#disabled'] = TRUE; $row['description']['#markup'] = $status; $row['#attributes']['class'][] = 'incompatible'; } // If this module requires other modules, add them to the array. foreach ($module->requires as $dependency => $version) { if (!isset($modules[$dependency])) { $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', array('@module' => Unicode::ucfirst($dependency))); $row['enable']['#disabled'] = TRUE; } elseif (empty($modules[$dependency]->hidden)) { $name = $modules[$dependency]->info['name']; // Disable the module's checkbox if it is incompatible with the // dependency's version. if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) { $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> version @version)', array('@module' => $name . $incompatible_version, '@version' => $modules[$dependency]->info['version'])); $row['enable']['#disabled'] = TRUE; } elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) { $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array('@module' => $name)); $row['enable']['#disabled'] = TRUE; } elseif ($modules[$dependency]->status) { $row['#requires'][$dependency] = $this->t('@module', array('@module' => $name)); } else { $row['#requires'][$dependency] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $name)); } } } // If this module is required by other modules, list those, and then make it // impossible to disable this one. foreach ($module->required_by as $dependent => $version) { if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) { if ($modules[$dependent]->status == 1 && $module->status == 1) { $row['#required_by'][$dependent] = $this->t('@module', array('@module' => $modules[$dependent]->info['name'])); $row['enable']['#disabled'] = TRUE; } else { $row['#required_by'][$dependent] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $modules[$dependent]->info['name'])); } } } return $row; }
/** * Returns the relative path of the theme. * * @return string * The relative path of the theme. */ public function getPath() { return $this->theme->getPath(); }
/** * {@inheritdoc} */ public function getActiveTheme(Extension $theme, array $base_themes = []) { $theme_path = $theme->getPath(); $values['path'] = $theme_path; $values['name'] = $theme->getName(); // @todo Remove in Drupal 9.0.x. $values['stylesheets_remove'] = $this->prepareStylesheetsRemove($theme, $base_themes); // Prepare libraries overrides from this theme and ancestor themes. This // allows child themes to easily remove CSS files from base themes and // modules. $values['libraries_override'] = []; // Get libraries overrides declared by base themes. foreach ($base_themes as $base) { if (!empty($base->info['libraries-override'])) { foreach ($base->info['libraries-override'] as $library => $override) { $values['libraries_override'][$base->getPath()][$library] = $override; } } } // Add libraries overrides declared by this theme. if (!empty($theme->info['libraries-override'])) { foreach ($theme->info['libraries-override'] as $library => $override) { $values['libraries_override'][$theme->getPath()][$library] = $override; } } // Get libraries extensions declared by base themes. foreach ($base_themes as $base) { if (!empty($base->info['libraries-extend'])) { foreach ($base->info['libraries-extend'] as $library => $extend) { if (isset($values['libraries_extend'][$library])) { // Merge if libraries-extend has already been defined for this // library. $values['libraries_extend'][$library] = array_merge($values['libraries_extend'][$library], $extend); } else { $values['libraries_extend'][$library] = $extend; } } } } // Add libraries extensions declared by this theme. if (!empty($theme->info['libraries-extend'])) { foreach ($theme->info['libraries-extend'] as $library => $extend) { if (isset($values['libraries_extend'][$library])) { // Merge if libraries-extend has already been defined for this // library. $values['libraries_extend'][$library] = array_merge($values['libraries_extend'][$library], $extend); } else { $values['libraries_extend'][$library] = $extend; } } } // Do basically the same as the above for libraries $values['libraries'] = array(); // Grab libraries from base theme foreach ($base_themes as $base) { if (!empty($base->libraries)) { foreach ($base->libraries as $library) { $values['libraries'][] = $library; } } } // Add libraries used by this theme. if (!empty($theme->libraries)) { foreach ($theme->libraries as $library) { $values['libraries'][] = $library; } } $values['engine'] = isset($theme->engine) ? $theme->engine : NULL; $values['owner'] = isset($theme->owner) ? $theme->owner : NULL; $values['extension'] = $theme; $base_active_themes = array(); foreach ($base_themes as $base_theme) { $base_active_themes[$base_theme->getName()] = $this->getActiveTheme($base_theme, array_slice($base_themes, 1)); } $values['base_themes'] = $base_active_themes; if (!empty($theme->info['regions'])) { $values['regions'] = $theme->info['regions']; } return new ActiveTheme($values); }
/** * Determines what project a given file object belongs to. * * @param \Drupal\Core\Extension\Extension $file * An extension object. * * @return string * The canonical project short name. */ function getProjectName(Extension $file) { $project_name = ''; if (isset($file->info['project'])) { $project_name = $file->info['project']; } elseif (strpos($file->getPath(), 'core/modules') === 0) { $project_name = 'drupal'; } return $project_name; }
/** * @param \Drupal\Core\Extension\Extension $extension * @return \Drupal\Console\Extension\Extension */ private function createExtension($extension) { $consoleExtension = new Extension($this->appRoot, $extension->getType(), $extension->getPathname(), $extension->getExtensionFilename()); $consoleExtension->unserialize($extension->serialize()); return $consoleExtension; }
/** * {@inheritdoc} */ public function addTheme(Extension $theme) { // @todo Remove this 100% unnecessary duplication of properties. foreach ($theme->info['stylesheets'] as $media => $stylesheets) { foreach ($stylesheets as $stylesheet => $path) { $theme->stylesheets[$media][$stylesheet] = $path; } } foreach ($theme->info['libraries'] as $library => $name) { $theme->libraries[$library] = $name; } if (isset($theme->info['engine'])) { $theme->engine = $theme->info['engine']; } if (isset($theme->info['base theme'])) { $theme->base_theme = $theme->info['base theme']; } $this->list[$theme->getName()] = $theme; }
/** * {@inheritdoc} */ public function getActiveTheme(Extension $theme, array $base_themes = []) { $theme_path = $theme->getPath(); $values['path'] = $theme_path; $values['name'] = $theme->getName(); // Prepare stylesheets from this theme as well as all ancestor themes. // We work it this way so that we can have child themes remove CSS files // easily from parent. $values['stylesheets_remove'] = array(); // Grab stylesheets from base theme. foreach ($base_themes as $base) { $base_theme_path = $base->getPath(); if (!empty($base->info['stylesheets-remove'])) { foreach ($base->info['stylesheets-remove'] as $css_file) { $css_file = $this->resolveStyleSheetPlaceholders($css_file); $values['stylesheets_remove'][$css_file] = $css_file; } } } // Add stylesheets used by this theme. if (!empty($theme->info['stylesheets-remove'])) { foreach ($theme->info['stylesheets-remove'] as $css_file) { $css_file = $this->resolveStyleSheetPlaceholders($css_file); $values['stylesheets_remove'][$css_file] = $css_file; } } // Do basically the same as the above for libraries $values['libraries'] = array(); // Grab libraries from base theme foreach ($base_themes as $base) { if (!empty($base->libraries)) { foreach ($base->libraries as $library) { $values['libraries'][] = $library; } } } // Add libraries used by this theme. if (!empty($theme->libraries)) { foreach ($theme->libraries as $library) { $values['libraries'][] = $library; } } $values['engine'] = isset($theme->engine) ? $theme->engine : NULL; $values['owner'] = isset($theme->owner) ? $theme->owner : NULL; $values['extension'] = $theme; $base_active_themes = array(); foreach ($base_themes as $base_theme) { $base_active_themes[$base_theme->getName()] = $this->getActiveTheme($base_theme, array_slice($base_themes, 1)); } $values['base_themes'] = $base_active_themes; if (!empty($theme->info['regions'])) { $values['regions'] = $theme->info['regions']; } return new ActiveTheme($values); }
/** * Creates a Libraries API extension object from a core extension object. * * @param \Drupal\Core\Extension\Extension $core_extension * The core extension object. * * @return \Drupal\libraries\Extension\ExtensionInterface * The Libraries API extension object. */ protected function wrapCoreExtension(CoreExtension $core_extension) { return new Extension($this->root, $core_extension->getType(), $core_extension->getPathname(), $core_extension->getExtensionFilename()); }
/** * {@inheritdoc} */ public function getFeaturesInfo(Extension $extension) { $features_info = NULL; $filename = $this->root . '/' . $extension->getPath() . '/' . $extension->getName() . '.features.yml'; if (file_exists($filename)) { $features_info = Yaml::decode(file_get_contents($filename)); } return $features_info; }
/** * {@inheritdoc} */ public function getFeaturesInfo(Extension $extension) { $module_name = $extension->getName(); if (isset($this->featureInfoCache[$module_name])) { return $this->featureInfoCache[$module_name]; } $features_info = NULL; $filename = $this->root . '/' . $extension->getPath() . '/' . $module_name . '.features.yml'; if (file_exists($filename)) { $features_info = Yaml::decode(file_get_contents($filename)); } $this->featureInfoCache[$module_name] = $features_info; return $features_info; }
/** * Loads the {$this->updateType}.php file for a given extension. * * @param \Drupal\Core\Extension\Extension $module * The extension of the module to load its file. */ protected function loadUpdateFile(Extension $module) { $filename = $this->root . '/' . $module->getPath() . '/' . $module->getName() . ".{$this->updateType}.php"; if (file_exists($filename)) { include_once $filename; } }
/** * {@inheritdoc} */ public function addTheme(Extension $theme) { foreach ($theme->info['libraries'] as $library => $name) { $theme->libraries[$library] = $name; } if (isset($theme->info['engine'])) { $theme->engine = $theme->info['engine']; } if (isset($theme->info['base theme'])) { $theme->base_theme = $theme->info['base theme']; } $this->list[$theme->getName()] = $theme; }
/** * {@inheritdoc} */ public function getExtensionInfo(Extension $extension) { return \Drupal::service('info_parser')->parse($extension->getPathname()); }