本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::getModuleList方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::getModuleList方法的具体用法?PHP ModuleHandlerInterface::getModuleList怎么用?PHP ModuleHandlerInterface::getModuleList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Extension\ModuleHandlerInterface
的用法示例。
在下文中一共展示了ModuleHandlerInterface::getModuleList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$modules = array_keys($this->moduleHandler->getModuleList());
sort($modules);
$form['list'] = array('#type' => 'checkboxes', '#options' => array_combine($modules, $modules), '#description' => t('Uninstall and then install the selected modules. <code>hook_uninstall()</code> and <code>hook_install()</code> will be executed and the schema version number will be set to the most recent update number. You may have to manually clear out any existing tables first if the module doesn\'t implement <code>hook_uninstall()</code>.'));
$form['submit'] = array('#value' => t('Reinstall'), '#type' => 'submit');
return $form;
}
示例2: getExtensions
/**
* {@inheritdoc}
*/
public function getExtensions()
{
foreach ($this->moduleHandler->getModuleList() as $module) {
(yield $this->wrapCoreExtension($module));
}
foreach ($this->themeHandler->listInfo() as $theme) {
(yield $this->wrapCoreExtension($theme));
}
}
示例3: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
$modules = $this->moduleHandler->getModuleList();
$themes = $this->themeHandler->listInfo();
$this->data['drupal_extension']['count'] = count($modules) + count($themes);
$this->data['drupal_extension']['modules'] = $modules;
$this->data['drupal_extension']['themes'] = $themes;
$this->data['drupal_extension']['installation_path'] = $this->root . '/';
}
示例4: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$modules = $this->moduleHandler->getModuleList();
$names = array();
foreach (array_keys($modules) as $name) {
$names[$name] = $this->moduleHandler->getName($name);
}
$form['data_module'] = array('#title' => $this->t('Module name'), '#type' => 'select', '#description' => $this->t('The module which sets this user data.'), '#default_value' => $this->options['data_module'], '#options' => $names);
$form['data_name'] = array('#title' => $this->t('Name'), '#type' => 'textfield', '#description' => $this->t('The name of the data key.'), '#default_value' => $this->options['data_name']);
}
示例5: getAllLibraries
private function getAllLibraries()
{
$modules = $this->moduleHandler->getModuleList();
$themes = $this->themeHandler->rebuildThemeData();
$extensions = array_merge($modules, $themes);
$libraries = [];
foreach ($extensions as $extensionName => $extension) {
$libraryFile = $extension->getPath() . '/' . $extensionName . '.libraries.yml';
if (is_file($this->appRoot . '/' . $libraryFile)) {
$libraries[$extensionName] = $this->libraryDiscovery->getLibrariesByExtension($extensionName);
}
}
return array_keys($libraries);
}
示例6: __construct
/**
* Constructs a ConfigMapperManager.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The cache backend.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* The typed config manager.
*/
public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManagerInterface $typed_config_manager, ThemeHandlerInterface $theme_handler)
{
$this->typedConfigManager = $typed_config_manager;
// Look at all themes and modules.
// @todo If the list of enabled modules and themes is changed, new
// definitions are not picked up immediately and obsolete definitions 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 enables e.g. 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 enabled themes.
$directories = array();
foreach ($module_handler->getModuleList() as $name => $module) {
$directories[$name] = $module->getPath();
}
foreach ($theme_handler->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);
$this->factory = new ContainerFactory($this);
// Let others alter definitions with hook_config_translation_info_alter().
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
$this->alterInfo('config_translation_info');
// Config translation only uses an info hook discovery, cache by language.
$cache_key = 'config_translation_info_plugins' . ':' . $language_manager->getCurrentLanguage()->getId();
$this->setCacheBackend($cache_backend, $cache_key, array('config_translation_info_plugins' => TRUE));
}
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Remove the key value store entry.
$account = $this->currentUser()->id();
$this->keyValueExpirable->delete($account);
// Gets list of modules prior to install process.
$before = $this->moduleHandler->getModuleList();
// Install the given modules.
if (!empty($this->modules['install'])) {
// Don't catch the exception that this can throw for missing dependencies:
// the form doesn't allow modules with unmet dependencies, so the only way
// this can happen is if the filesystem changed between form display and
// submit, in which case the user has bigger problems.
try {
$this->moduleInstaller->install(array_keys($this->modules['install']));
} catch (PreExistingConfigException $e) {
$config_objects = $e->flattenConfigObjects($e->getConfigObjects());
drupal_set_message($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', array('%config_names' => implode(', ', $config_objects), '@extension' => $this->modules['install'][$e->getExtension()])), 'error');
return;
} catch (UnmetDependenciesException $e) {
drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]), 'error');
return;
}
}
// Gets module list after install process, flushes caches and displays a
// message if there are changes.
if ($before != $this->moduleHandler->getModuleList()) {
drupal_set_message($this->t('The configuration options have been saved.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}
示例8: __construct
/**
* Constructs a TwigEnvironment object and stores cache and storage
* internally.
*/
public function __construct(\Twig_LoaderInterface $loader = NULL, $options = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
{
// @todo Pass as arguments from the DIC.
$this->cache_object = \Drupal::cache();
// Ensure that twig.engine is loaded, given that it is needed to render a
// template because functions like twig_drupal_escape_filter are called.
require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine';
// Set twig path namespace for themes and modules.
$namespaces = array();
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) {
$templatesDirectory = $path . '/templates';
if (file_exists($templatesDirectory)) {
$loader->addPath($templatesDirectory, $name);
}
}
$this->templateClasses = array();
$this->stringLoader = new \Twig_Loader_String();
parent::__construct($loader, $options);
}
示例9: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Retrieve a list of modules to install and their dependencies.
$modules = $this->buildModuleList($form_state);
// Check if we have to install any dependencies. If there is one or more
// dependencies that are not installed yet, redirect to the confirmation
// form.
if (!empty($modules['dependencies']) || !empty($modules['missing'])) {
// Write the list of changed module states into a key value store.
$account = $this->currentUser()->id();
$this->keyValueExpirable->setWithExpire($account, $modules, 60);
// Redirect to the confirmation form.
$form_state->setRedirect('system.modules_list_confirm');
// We can exit here because at least one modules has dependencies
// which we have to prompt the user for in a confirmation form.
return;
}
// Gets list of modules prior to install process.
$before = $this->moduleHandler->getModuleList();
// There seem to be no dependencies that would need approval.
if (!empty($modules['install'])) {
$this->moduleHandler->install(array_keys($modules['install']));
}
// Gets module list after install process, flushes caches and displays a
// message if there are changes.
if ($before != $this->moduleHandler->getModuleList()) {
drupal_set_message(t('The configuration options have been saved.'));
}
}
示例10: assignConfigPackage
/**
* {@inheritdoc}
*/
public function assignConfigPackage($package_name, array $item_names, $force = FALSE)
{
$config_collection = $this->getConfigCollection();
$module_list = $this->moduleHandler->getModuleList();
$packages =& $this->packages;
if (isset($packages[$package_name])) {
$package =& $packages[$package_name];
} else {
throw new \Exception($this->t('Failed to package @package_name. Package not found.', ['@package_name' => $package_name]));
}
foreach ($item_names as $item_name) {
if (isset($config_collection[$item_name])) {
// Add to the package if:
// - force is set or
// - the item hasn't already been assigned elsewhere, and
// - the package hasn't been excluded.
// - and the item isn't already in the package.
// Determine if the item is provided by an extension.
$extension_provided = $config_collection[$item_name]->isExtensionProvided() === TRUE;
$already_assigned = !empty($config_collection[$item_name]->getPackage());
// If this is the profile package, we can reassign extension-provided configuration.
$is_profile_package = $this->getAssigner()->getBundle($package->getBundle())->isProfilePackage($package->getMachineName());
// An item is assignable if:
// - it is not extension provided or this is the profile package, and
// - it is not flagged as excluded.
$assignable = (!$extension_provided || $is_profile_package) && !$config_collection[$item_name]->isExcluded();
$excluded_from_package = in_array($package_name, $config_collection[$item_name]->getPackageExcluded());
$already_in_package = in_array($item_name, $package->getConfig());
if (($force || !$already_assigned && $assignable && !$excluded_from_package) && !$already_in_package) {
// Add the item to the package's config array.
$package->appendConfig($item_name);
// Mark the item as already assigned.
$config_collection[$item_name]->setPackage($package_name);
$module_dependencies = [];
// Add a dependency on the extension that provides this configuration
// type.
if ($config_collection[$item_name]->getType() != static::SYSTEM_SIMPLE_CONFIG) {
$provider = $this->entityManager->getDefinition($config_collection[$item_name]->getType())->getProvider();
// Ensure the provider is an installed module and not, for example,
// 'core'.
if (isset($module_list[$provider])) {
$module_dependencies[] = $provider;
}
}
// For configuration in the InstallStorage::CONFIG_INSTALL_DIRECTORY
// directory, set any module dependencies of the configuration item
// as package dependencies.
// As its name implies, the core-provided
// InstallStorage::CONFIG_OPTIONAL_DIRECTORY should not create
// dependencies.
if ($config_collection[$item_name]->getSubdirectory() === InstallStorage::CONFIG_INSTALL_DIRECTORY && isset($config_collection[$item_name]->getData()['dependencies']['module'])) {
$module_dependencies = array_merge($module_dependencies, $config_collection[$item_name]->getData()['dependencies']['module']);
}
$package->setDependencies($this->mergeUniqueItems($package->getDependencies(), $module_dependencies));
}
}
}
$this->setConfigCollection($config_collection);
}
示例11: getModuleNames
/**
* Returns all module names.
*
* @return string[]
* Returns the human readable names of all modules keyed by machine name.
*/
protected function getModuleNames()
{
$modules = array();
foreach (array_keys($this->moduleHandler->getModuleList()) as $module) {
$modules[$module] = $this->moduleHandler->getName($module);
}
asort($modules);
return $modules;
}
示例12: getModuleNames
/**
* Returns all module names.
*
* @return string[]
* Returns the human readable names of all modules keyed by machine name.
*/
protected function getModuleNames()
{
$modules = array();
$module_info = $this->systemRebuildModuleData();
foreach (array_keys($this->moduleHandler->getModuleList()) as $module) {
$modules[$module] = $module_info[$module]->info['name'];
}
asort($modules);
return $modules;
}
示例13: getModulesScript
/**
* List of modules enabled for insertion into the script docblock.
*
* @return string
* The formatted list of enabled modules.
*/
protected function getModulesScript()
{
$output = '';
$modules = $this->moduleHandler->getModuleList();
ksort($modules);
foreach ($modules as $module => $filename) {
$output .= " * - {$module}\n";
}
return rtrim($output, "\n");
}
示例14: __construct
/**
* Constructs a new FilesystemLoader object.
*
* @param string|array $paths
* A path or an array of paths to check for templates.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler service.
*/
public function __construct($paths = array(), ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler)
{
parent::__construct($paths);
// Add namespaced paths for modules and themes.
$namespaces = array();
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);
}
}
示例15: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Remove the key value store entry.
$account = $this->currentUser()->id();
$this->keyValueExpirable->delete($account);
// Gets list of modules prior to install process.
$before = $this->moduleHandler->getModuleList();
// Install the given modules.
if (!empty($this->modules['install'])) {
$this->moduleHandler->install(array_keys($this->modules['install']));
}
// Gets module list after install process, flushes caches and displays a
// message if there are changes.
if ($before != $this->moduleHandler->getModuleList()) {
drupal_set_message($this->t('The configuration options have been saved.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}