当前位置: 首页>>代码示例>>PHP>>正文


PHP ModuleHandlerInterface::load方法代码示例

本文整理汇总了PHP中Drupal\Core\Extension\ModuleHandlerInterface::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleHandlerInterface::load方法的具体用法?PHP ModuleHandlerInterface::load怎么用?PHP ModuleHandlerInterface::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Extension\ModuleHandlerInterface的用法示例。


在下文中一共展示了ModuleHandlerInterface::load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: install

 /**
  * {@inheritdoc}
  */
 public function install(array $module_list, $enable_dependencies = TRUE)
 {
     $extension_config = \Drupal::configFactory()->getEditable('core.extension');
     if ($enable_dependencies) {
         // Get all module data so we can find dependencies and sort.
         $module_data = system_rebuild_module_data();
         $module_list = $module_list ? array_combine($module_list, $module_list) : array();
         if ($missing_modules = array_diff_key($module_list, $module_data)) {
             // One or more of the given modules doesn't exist.
             throw new MissingDependencyException(SafeMarkup::format('Unable to install modules %modules due to missing modules %missing.', array('%modules' => implode(', ', $module_list), '%missing' => implode(', ', $missing_modules))));
         }
         // Only process currently uninstalled modules.
         $installed_modules = $extension_config->get('module') ?: array();
         if (!($module_list = array_diff_key($module_list, $installed_modules))) {
             // Nothing to do. All modules already installed.
             return TRUE;
         }
         // Add dependencies to the list. The new modules will be processed as
         // the while loop continues.
         while (list($module) = each($module_list)) {
             foreach (array_keys($module_data[$module]->requires) as $dependency) {
                 if (!isset($module_data[$dependency])) {
                     // The dependency does not exist.
                     throw new MissingDependencyException(SafeMarkup::format('Unable to install modules: module %module is missing its dependency module %dependency.', array('%module' => $module, '%dependency' => $dependency)));
                 }
                 // Skip already installed modules.
                 if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) {
                     $module_list[$dependency] = $dependency;
                 }
             }
         }
         // Set the actual module weights.
         $module_list = array_map(function ($module) use($module_data) {
             return $module_data[$module]->sort;
         }, $module_list);
         // Sort the module list by their weights (reverse).
         arsort($module_list);
         $module_list = array_keys($module_list);
     }
     // Required for module installation checks.
     include_once $this->root . '/core/includes/install.inc';
     /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */
     $config_installer = \Drupal::service('config.installer');
     $sync_status = $config_installer->isSyncing();
     if ($sync_status) {
         $source_storage = $config_installer->getSourceStorage();
     }
     $modules_installed = array();
     foreach ($module_list as $module) {
         $enabled = $extension_config->get("module.{$module}") !== NULL;
         if (!$enabled) {
             // Throw an exception if the module name is too long.
             if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
                 throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array('%name' => $module, '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH)));
             }
             // Check the validity of the default configuration. This will throw
             // exceptions if the configuration is not valid.
             $config_installer->checkConfigurationToInstall('module', $module);
             $extension_config->set("module.{$module}", 0)->set('module', module_config_sort($extension_config->get('module')))->save();
             // Prepare the new module list, sorted by weight, including filenames.
             // This list is used for both the ModuleHandler and DrupalKernel. It
             // needs to be kept in sync between both. A DrupalKernel reboot or
             // rebuild will automatically re-instantiate a new ModuleHandler that
             // uses the new module list of the kernel. However, DrupalKernel does
             // not cause any modules to be loaded.
             // Furthermore, the currently active (fixed) module list can be
             // different from the configured list of enabled modules. For all active
             // modules not contained in the configured enabled modules, we assume a
             // weight of 0.
             $current_module_filenames = $this->moduleHandler->getModuleList();
             $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
             $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
             $module_filenames = array();
             foreach ($current_modules as $name => $weight) {
                 if (isset($current_module_filenames[$name])) {
                     $module_filenames[$name] = $current_module_filenames[$name];
                 } else {
                     $module_path = drupal_get_path('module', $name);
                     $pathname = "{$module_path}/{$name}.info.yml";
                     $filename = file_exists($module_path . "/{$name}.module") ? "{$name}.module" : NULL;
                     $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename);
                 }
             }
             // Update the module handler in order to load the module's code.
             // This allows the module to participate in hooks and its existence to
             // be discovered by other modules.
             // The current ModuleHandler instance is obsolete with the kernel
             // rebuild below.
             $this->moduleHandler->setModuleList($module_filenames);
             $this->moduleHandler->load($module);
             module_load_install($module);
             // Clear the static cache of system_rebuild_module_data() to pick up the
             // new module, since it merges the installation status of modules into
             // its statically cached list.
             drupal_static_reset('system_rebuild_module_data');
             // Update the kernel to include it.
             $this->updateKernel($module_filenames);
//.........这里部分代码省略.........
开发者ID:brstde,项目名称:gap1,代码行数:101,代码来源:ModuleInstaller.php

示例2: install

 /**
  * {@inheritdoc}
  */
 public function install(array $module_list, $enable_dependencies = TRUE)
 {
     $extension_config = \Drupal::configFactory()->getEditable('core.extension');
     if ($enable_dependencies) {
         // Get all module data so we can find dependencies and sort.
         $module_data = system_rebuild_module_data();
         $module_list = $module_list ? array_combine($module_list, $module_list) : array();
         if ($missing_modules = array_diff_key($module_list, $module_data)) {
             // One or more of the given modules doesn't exist.
             throw new MissingDependencyException(sprintf('Unable to install modules %s due to missing modules %s.', implode(', ', $module_list), implode(', ', $missing_modules)));
         }
         // Only process currently uninstalled modules.
         $installed_modules = $extension_config->get('module') ?: array();
         if (!($module_list = array_diff_key($module_list, $installed_modules))) {
             // Nothing to do. All modules already installed.
             return TRUE;
         }
         // Add dependencies to the list. The new modules will be processed as
         // the while loop continues.
         while (list($module) = each($module_list)) {
             foreach (array_keys($module_data[$module]->requires) as $dependency) {
                 if (!isset($module_data[$dependency])) {
                     // The dependency does not exist.
                     throw new MissingDependencyException("Unable to install modules: module '{$module}' is missing its dependency module {$dependency}.");
                 }
                 // Skip already installed modules.
                 if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) {
                     $module_list[$dependency] = $dependency;
                 }
             }
         }
         // Set the actual module weights.
         $module_list = array_map(function ($module) use($module_data) {
             return $module_data[$module]->sort;
         }, $module_list);
         // Sort the module list by their weights (reverse).
         arsort($module_list);
         $module_list = array_keys($module_list);
     }
     // Required for module installation checks.
     include_once $this->root . '/core/includes/install.inc';
     /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */
     $config_installer = \Drupal::service('config.installer');
     $sync_status = $config_installer->isSyncing();
     if ($sync_status) {
         $source_storage = $config_installer->getSourceStorage();
     }
     $modules_installed = array();
     foreach ($module_list as $module) {
         $enabled = $extension_config->get("module.{$module}") !== NULL;
         if (!$enabled) {
             // Throw an exception if the module name is too long.
             if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
                 throw new ExtensionNameLengthException("Module name '{$module}' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
             }
             // Check the validity of the default configuration. This will throw
             // exceptions if the configuration is not valid.
             $config_installer->checkConfigurationToInstall('module', $module);
             // Save this data without checking schema. This is a performance
             // improvement for module installation.
             $extension_config->set("module.{$module}", 0)->set('module', module_config_sort($extension_config->get('module')))->save(TRUE);
             // Prepare the new module list, sorted by weight, including filenames.
             // This list is used for both the ModuleHandler and DrupalKernel. It
             // needs to be kept in sync between both. A DrupalKernel reboot or
             // rebuild will automatically re-instantiate a new ModuleHandler that
             // uses the new module list of the kernel. However, DrupalKernel does
             // not cause any modules to be loaded.
             // Furthermore, the currently active (fixed) module list can be
             // different from the configured list of enabled modules. For all active
             // modules not contained in the configured enabled modules, we assume a
             // weight of 0.
             $current_module_filenames = $this->moduleHandler->getModuleList();
             $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
             $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
             $module_filenames = array();
             foreach ($current_modules as $name => $weight) {
                 if (isset($current_module_filenames[$name])) {
                     $module_filenames[$name] = $current_module_filenames[$name];
                 } else {
                     $module_path = drupal_get_path('module', $name);
                     $pathname = "{$module_path}/{$name}.info.yml";
                     $filename = file_exists($module_path . "/{$name}.module") ? "{$name}.module" : NULL;
                     $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename);
                 }
             }
             // Update the module handler in order to load the module's code.
             // This allows the module to participate in hooks and its existence to
             // be discovered by other modules.
             // The current ModuleHandler instance is obsolete with the kernel
             // rebuild below.
             $this->moduleHandler->setModuleList($module_filenames);
             $this->moduleHandler->load($module);
             module_load_install($module);
             // Clear the static cache of system_rebuild_module_data() to pick up the
             // new module, since it merges the installation status of modules into
             // its statically cached list.
             drupal_static_reset('system_rebuild_module_data');
//.........这里部分代码省略.........
开发者ID:eigentor,项目名称:tommiblog,代码行数:101,代码来源:ModuleInstaller.php


注:本文中的Drupal\Core\Extension\ModuleHandlerInterface::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。