getModuleList example

// 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 = [];
        foreach ($current_modules as $name => $weight) {
          if (isset($current_module_filenames[$name])) {
            $module_filenames[$name] = $current_module_filenames[$name];
          }
          else {
            $module_path = \Drupal::service('extension.list.module')->getPath($name);
            $pathname = "$module_path/$name.info.yml";
            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
            
// Look at all themes and modules.       // @todo If the list of installed 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 installs (for instance, 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 installed themes.       $directories = [];
      foreach ($this->moduleHandler->getModuleList() as $name => $module) {
        $directories[$name] = $module->getPath();
      }
      foreach ($this->themeHandler->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->assertArrayHasKey('source_module', $definition, "No source_module property in '$id'");
    }
  }

  /** * Enable all available modules. */
  protected function enableAllModules() {
    // Install all available modules.     $module_handler = $this->container->get('module_handler');
    $modules = $this->coreModuleListDataProvider();
    $modules_enabled = $module_handler->getModuleList();
    $modules_to_enable = array_keys(array_diff_key($modules$modules_enabled));
    $this->enableModules($modules_to_enable);
  }

  /** * Tests that modules exist for all field plugins. */
  public function testFieldProvidersExist() {
    $expected_mappings = [
      'userreference' => [
        'source_module' => 'userreference',
        
$this->assertFalse($module_handler->isLoaded());
    $module_handler->loadAll();
    $this->assertTrue($module_handler->isLoaded());
  }

  /** * Confirm we get back the modules set in the constructor. * * @covers ::getModuleList */
  public function testGetModuleList() {
    $this->assertEquals($this->getModuleHandler()->getModuleList()[
      'module_handler_test' => new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'),
    ]);
  }

  /** * Confirm we get back a module from the module list. * * @covers ::getModule */
  public function testGetModuleWithExistingModule() {
    $this->assertEquals($this->getModuleHandler()->getModule('module_handler_test')new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'));
  }
// Install the module_test module.     \Drupal::service('module_installer')->install(['module_test']);

    // Assert that the \Drupal::moduleHandler() instance has been replaced.     $this->assertNotSame(\Drupal::moduleHandler()$module_handler, 'The \Drupal::moduleHandler() instance has been replaced during \Drupal::moduleHandler()->install().');

    // Assert that module_test.module is now included.     $this->assertTrue(function_exists('module_test_modules_installed'),
      'The file module_test.module was successfully included.');

    $this->assertArrayHasKey('module_test', \Drupal::moduleHandler()->getModuleList());

    $this->assertTrue(\Drupal::moduleHandler()->hasImplementations('modules_installed', 'module_test'),
      'module_test implements hook_modules_installed().');

    $this->assertTrue(\Drupal::moduleHandler()->hasImplementations('module_implements_alter', 'module_test'),
      'module_test implements hook_module_implements_alter().');

    // Assert that module_test.implementations.inc is not included yet.     $this->assertFalse(function_exists('module_test_altered_test_hook'),
      'The file module_test.implementations.inc is not included yet.');

    
return $all_permissions;
  }

  /** * Returns all module names. * * @return string[] * Returns the human readable names of all modules keyed by machine name. */
  protected function getModuleNames() {
    $modules = [];
    foreach (array_keys($this->moduleHandler->getModuleList()) as $module) {
      $modules[$module] = $this->moduleHandler->getName($module);
    }
    asort($modules);
    return $modules;
  }

}
$this->assertContains($datum$declared_unique[MigrationState::NOT_FINISHED]sprintf("No migration found for version '%s' with source_module '%s' and destination_module '%s' declared in module '%s'", $version$data[1]$data[2]$data[0]));
    }
  }

  /** * Enable all available modules. */
  protected function enableAllModules() {
    // Install all available modules.     $module_handler = $this->container->get('module_handler');
    $modules = $this->coreModuleListDataProvider();
    $modules_enabled = $module_handler->getModuleList();
    $modules_to_enable = array_keys(array_diff_key($modules$modules_enabled));
    $this->enableModules($modules_to_enable);
    return $modules;
  }

}
$this->fail("The $update_name() update function from the $module module did not run.");
            }
          }
        }
      }

      // Ensure that the container is updated if any modules are installed or       // uninstalled during the update.       /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
      $module_handler = $this->container->get('module_handler');
      $config_module_list = $this->config('core.extension')->get('module');
      $module_handler_list = $module_handler->getModuleList();
      $modules_installed = FALSE;
      // Modules that are in configuration but not the module handler have been       // installed.       /** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
      $module_list = $this->container->get('extension.list.module');
      foreach (array_keys(array_diff_key($config_module_list$module_handler_list)) as $module) {
        $module_handler->addModule($module$module_list->getPath($module));
        $modules_installed = TRUE;
      }
      $modules_uninstalled = FALSE;
      $module_handler_list = $module_handler->getModuleList();
      
$options['data_name'] = ['default' => ''];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $modules = $this->moduleHandler->getModuleList();
    $names = [];
    foreach (array_keys($modules) as $name) {
      $names[$name] = $this->moduleHandler->getName($name);
    }

    $form['data_module'] = [
      '#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,
    ];
// Verify that hook_help() section title and description appear.     $this->assertSession()->responseContains('<h2>Module overviews</h2>');
    $this->assertSession()->responseContains('<p>Module overviews are provided by modules. Overviews available for your installed modules:</p>');

    // Verify that an empty section is handled correctly.     $this->assertSession()->responseContains('<h2>Empty section</h2>');
    $this->assertSession()->responseContains('<p>This description should appear.</p>');
    $this->assertSession()->pageTextContains('There is currently nothing in this section.');

    // Make sure links are properly added for modules implementing hook_help().     foreach ($this->getModuleList() as $module => $name) {
      $this->assertSession()->linkExists($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name]));
    }

    // Ensure a module which does not provide a module overview page is handled     // correctly.     $this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
    $this->assertSession()->pageTextContains('No help is available for module ' . \Drupal::moduleHandler()->getName('help_test'));

    // Verify that the order of topics is alphabetical by displayed module     // name, by checking the order of some modules, including some that would     // have a different order if it was done by machine name instead.
return new ActiveTheme($values);
  }

  /** * Gets all extensions. * * @return array */
  protected function getExtensions() {
    if (!isset($this->extensions)) {
      $this->extensions = array_merge($this->moduleHandler->getModuleList()$this->themeHandler->listInfo());
    }
    return $this->extensions;
  }

  /** * Gets CSS file where tokens have been resolved. * * @param string $css_file * CSS file which may contain tokens. * * @return string * CSS file where placeholders are replaced. * * @todo Remove in Drupal 9.0.x. */

  protected function assertModuleList(array $expected_values, string $condition): void {
    $expected_values = array_values(array_unique($expected_values));
    $enabled_modules = array_keys($this->container->get('module_handler')->getModuleList());
    $this->assertEquals($expected_values$enabled_modulesnew FormattableMarkup('@condition: extension handler returns correct results', ['@condition' => $condition]));
  }

  /** * Tests dependency resolution. * * Intentionally using fake dependencies added via hook_system_info_alter() * for modules that normally do not have any dependencies. * * To simplify things further, all of the manipulated modules are either * purely UI-facing or live at the "bottom" of all dependency chains. * * @see module_test_system_info_alter() * @see https://www.drupal.org/files/issues/dep.gv__0.png */
class UpdateRegistryFactory implements ContainerAwareInterface {

  use ContainerAwareTrait;

  /** * Creates a new UpdateRegistry instance. * * @return \Drupal\Core\Update\UpdateRegistry * The update registry instance. */
  public function create() {
    $extensions = array_merge(array_keys($this->container->get('module_handler')->getModuleList())array_keys($this->container->get('theme_handler')->listInfo()));
    return new UpdateRegistry($this->container->getParameter('app.root')$this->container->getParameter('site.path')$extensions$this->container->get('keyvalue')->get('post_update'));
  }

}

  public function __construct(MigrateFieldPluginManagerInterface $fieldPluginManager, ModuleHandlerInterface $moduleHandler, MessengerInterface $messenger, TranslationInterface $stringTranslation) {
    $this->fieldPluginManager = $fieldPluginManager;
    $this->moduleHandler = $moduleHandler;
    $this->enabledModules = array_keys($this->moduleHandler->getModuleList());
    $this->enabledModules[] = 'core';
    $this->messenger = $messenger;
    $this->stringTranslation = $stringTranslation;
  }

  /** * Gets the upgrade states for all enabled source modules. * * @param string $version * The legacy drupal version. * @param array $source_system_data * The data from the source site system table. * @param array $migrations * An array of migrations. * * @return array * An associative array of data with keys of state, source modules and a * value which is a comma separated list of destination modules. */
/** * Gets the name of a provider. * * @param string $provider * The machine name of a plugin provider. * * @return string * The human-readable module name if it exists, otherwise the * machine-readable name passed. */
  protected function getProviderName($provider) {
    $list = $this->getModuleHandler()->getModuleList();
    // If the module exists, return its human-readable name.     if (isset($list[$provider])) {
      return $this->getModuleHandler()->getName($provider);
    }
    // Otherwise, return the machine name.     return $provider;
  }

  /** * Returns the module handler used. * * @return \Drupal\Core\Extension\ModuleHandlerInterface * The module handler. */
Home | Imprint | This part of the site doesn't use cookies.