moduleHandler example


      }
    }

    // Get the declared migration state information from .migrate_drupal.yml     // and build an array of source modules and there migration state. The     // destination is not used yet but can be later for validating the     // source/destination pairs with the actual source/destination pairs in the     // migrate plugins.     $system_info = (new YamlDiscovery('migrate_drupal', array_map(function D$value) {
      return $value . '/migrations/state/';
    }, \Drupal::moduleHandler()->getModuleDirectories())))->findAll();

    $declared = [
      MigrationState::FINISHED => [],
      MigrationState::NOT_FINISHED => [],
    ];
    foreach ($system_info as $module => $info) {
      foreach (array_keys($declared) as $state) {
        if (isset($info[$state][$version])) {
          foreach ($info[$state][$version] as $source => $destination) {
            // Do not add the source module i18nstrings or i18_string. The             // 18n migrations can have up to three source modules but only one
'test_theme_updates',
      ],
    ];
    // Create an install profile that uses the test theme.     $path = $this->siteDirectory . '/profiles/theme_test_profile';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/theme_test_profile.info.yml", Yaml::encode($info));

    // Create a system.theme.yml file for the profile so the test theme is used.     $path = $this->siteDirectory . '/profiles/theme_test_profile/config/install';
    mkdir($path, 0777, TRUE);
    $theme_config = Yaml::decode(file_get_contents(\Drupal::moduleHandler()->getModule('system')->getPath() . '/config/install/system.theme.yml'));
    $theme_config['default'] = 'test_theme_updates';
    file_put_contents("$path/system.theme.yml", Yaml::encode($theme_config));
  }

  /** * Tests that after installing the profile there are no outstanding updates. */
  public function testMaintenanceThemeUpdateRegistration() {
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    
'migrate_drupal',
    'options',
    'file',
  ];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $module_handler = \Drupal::moduleHandler();
    if ($module_handler->moduleExists('node')) {
      $this->installEntitySchema('node');
    }
    if ($module_handler->moduleExists('comment')) {
      $this->installEntitySchema('comment');
    }
    if ($module_handler->moduleExists('taxonomy')) {
      $this->installEntitySchema('taxonomy_term');
    }
    if ($module_handler->moduleExists('user')) {
      $this->installEntitySchema('user');
    }
protected $profile = 'testing';

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Ensure the Update module is installed. */
  public function testUpdateModuleInstall() {
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('update'));
  }

  /** * {@inheritdoc} */
  protected function installParameters() {
    $params = parent::installParameters();
    $params['forms']['install_configure_form']['enable_update_status_module'] = TRUE;
    return $params;
  }

}
$this->assertSession()->pageTextContains('hook_modules_installed fired for help');
    $this->assertModuleSuccessfullyInstalled('help');

    // Test help for the required modules.     foreach ($required_modules as $name => $module) {
      $this->assertHelp($name$module->info['name']);
    }

    // Go through each module in the list and try to install and uninstall     // it with its dependencies.     foreach ($all_modules as $name => $module) {
      $was_installed_list = \Drupal::moduleHandler()->getModuleList();

      // Start a list of modules that we expect to be installed this time.       $modules_to_install = [$name];
      foreach (array_keys($module->requires) as $dependency) {
        if (isset($all_modules[$dependency])) {
          $modules_to_install[] = $dependency;
        }
      }

      // Check that each module is not yet enabled and does not have any       // database tables yet.

  public function testNodeThemeHookSuggestions() {
    // Create node to be rendered.     $node = $this->drupalCreateNode();
    $view_mode = 'full';

    // Simulate theming of the node.     $build = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node$view_mode);

    $variables['elements'] = $build;
    $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_node', [$variables]);

    $this->assertEquals(['node__full', 'node__page', 'node__page__full', 'node__' . $node->id(), 'node__' . $node->id() . '__full']$suggestions, 'Found expected node suggestions.');

    // Change the view mode.     $view_mode = 'node.my_custom_view_mode';
    $build = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node$view_mode);

    $variables['elements'] = $build;
    $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_node', [$variables]);

    $this->assertEquals(['node__node_my_custom_view_mode', 'node__page', 'node__page__node_my_custom_view_mode', 'node__' . $node->id(), 'node__' . $node->id() . '__node_my_custom_view_mode']$suggestions, 'Found expected node suggestions.');
  }


      // Let the display know which view mode was originally requested.       $display->originalMode = $view_mode;

      // Let modules alter the display.       $display_context = [
        'entity_type' => $entity_type,
        'bundle' => $bundle,
        'view_mode' => $view_mode,
      ];
      \Drupal::moduleHandler()->alter('entity_view_display', $display$display_context);

      $displays_by_bundle[$bundle] = $display;
    }

    return $displays_by_bundle;
  }

  /** * Returns the display object used to render an entity. * * See the collectRenderDisplays() method for details. * * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity being rendered. * @param string $view_mode * The view mode. * * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface * The display object that should be used to render the entity. * * @see \Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays() */

  protected $moduleHandler;

  /** * Gets the module handler. * * @return \Drupal\Core\Extension\ModuleHandlerInterface * The module handler. */
  protected function moduleHandler() {
    if (!$this->moduleHandler) {
      $this->moduleHandler = \Drupal::moduleHandler();
    }
    return $this->moduleHandler;
  }

  /** * Sets the module handler for this handler. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. * * @return $this */
// Invoke hook_entity_access() and hook_ENTITY_TYPE_access(). Hook results     // take precedence over overridden implementations of     // EntityAccessControlHandler::checkAccess(). Entities that have checks that     // need to be done before the hook is invoked should do so by overriding     // this method.
    // We grant access to the entity if both of these conditions are met:     // - No modules say to deny access.     // - At least one module says to grant access.     $access = array_merge(
      $this->moduleHandler()->invokeAll('entity_access', [$entity$operation$account]),
      $this->moduleHandler()->invokeAll($entity->getEntityTypeId() . '_access', [$entity$operation$account])
    );

    $return = $this->processAccessHookResults($access);

    // Also execute the default access check except when the access result is     // already forbidden, as in that case, it can not be anything else.     if (!$return->isForbidden()) {
      $return = $return->orIf($this->checkAccess($entity$operation$account));
    }
    $result = $this->setCache($return$cid$operation$langcode$account);
    

  public function getAccountName() {
    return $this->name;
  }

  /** * {@inheritdoc} */
  public function getDisplayName() {
    $name = $this->name ?: \Drupal::config('user.settings')->get('anonymous');
    \Drupal::moduleHandler()->alter('user_format_name', $name$this);
    return $name;
  }

  /** * {@inheritdoc} */
  public function getEmail() {
    return $this->mail;
  }

  /** * {@inheritdoc} */
/** * Modules to enable. * * @var array */
  protected static $modules = ['views', 'views_ui', 'user'];

  /** * Tests the ViewsUIController::autocompleteTag() function. */
  public function testViewsUiAutocompleteTag() {
    \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');

    // Save 15 views with a tag.     $tags = [];
    for ($i = 0; $i < 16; $i++) {
      $suffix = $i % 2 ? 'odd' : 'even';
      $tag = 'autocomplete_tag_test_' . $suffix . $this->randomMachineName();
      $tags[] = $tag;
      View::create(['tag' => $tag, 'id' => $this->randomMachineName()])->save();
    }

    // Make sure just ten results are returned.
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $module_handler = \Drupal::moduleHandler();
    $module_handler->loadInclude('locale', 'inc', 'locale.compare');
    $module_handler->loadInclude('locale', 'inc', 'locale.fetch');
    $admin_user = $this->drupalCreateUser([
      'administer modules',
      'administer site configuration',
      'administer languages',
      'access administration pages',
      'translate interface',
    ]);
    $this->drupalLogin($admin_user);
    // We use German as test language. This language must match the translation
    // toolbar presentation.     $breakpoints = static::breakpointManager()->getBreakpointsByGroup('toolbar');
    if (!empty($breakpoints)) {
      $media_queries = [];
      foreach ($breakpoints as $id => $breakpoint) {
        $media_queries[$id] = $breakpoint->getMediaQuery();
      }

      $element['#attached']['drupalSettings']['toolbar']['breakpoints'] = $media_queries;
    }

    $module_handler = static::moduleHandler();
    // Get toolbar items from all modules that implement hook_toolbar().     $items = $module_handler->invokeAll('toolbar');
    // Allow for altering of hook_toolbar().     $module_handler->alter('toolbar', $items);
    // Sort the children.     uasort($items['\Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);

    // Merge in the original toolbar values.     $element = array_merge($element$items);

    // Assign each item a unique ID, based on its key.

  protected function setUpCurrentUser(array $values = [], array $permissions = []$admin = FALSE) {
    $values += [
      'name' => $this->randomMachineName(),
    ];

    // In many cases the anonymous user account is fine for testing purposes,     // however, if we need to create a user with a non-empty ID, we need also     // the "sequences" table.     if (!\Drupal::moduleHandler()->moduleExists('system')) {
      $values['uid'] = 0;
    }
    if ($this instanceof KernelTestBase && (!isset($values['uid']) || $values['uid'])) {
      try {
        $this->installSchema('system', ['sequences']);
      }
      catch (SchemaObjectExistsException $e) {
      }
    }

    // Creating an administrator or assigning custom permissions would result in
public function testThemeInfoAlter() {
    $name = 'stark';
    $this->container->get('state')->set('module_test.hook_system_info_alter', TRUE);

    $this->themeInstaller()->install([$name]);

    $themes = $this->themeHandler()->listInfo();
    $this->assertFalse(isset($themes[$name]->info['regions']['test_region']));

    // Install module_test.     $this->moduleInstaller()->install(['module_test'], FALSE);
    $this->assertTrue($this->moduleHandler()->moduleExists('module_test'));

    $themes = $this->themeHandler()->listInfo();
    $this->assertTrue(isset($themes[$name]->info['regions']['test_region']));

    // Legacy assertions.     // @todo Remove once theme initialization/info has been modernized.     // @see https://www.drupal.org/node/2228093     $info = \Drupal::service('extension.list.theme')->getExtensionInfo($name);
    $this->assertTrue(isset($info['regions']['test_region']));
    $regions = system_region_list($name);
    $this->assertTrue(isset($regions['test_region']));
    
Home | Imprint | This part of the site doesn't use cookies.