moduleExists example

// Teaser view: display the number of comments that have been posted,           // or a link to add new comments if the user has permission, the           // entity is open to new comments, and there currently are none.           if ($this->currentUser->hasPermission('access comments')) {
            if (!empty($entity->get($field_name)->comment_count)) {
              $links['comment-comments'] = [
                'title' => $this->formatPlural($entity->get($field_name)->comment_count, '1 comment', '@count comments'),
                'attributes' => ['title' => $this->t('Jump to the first comment.')],
                'fragment' => 'comments',
                'url' => $entity->toUrl(),
              ];
              if ($this->moduleHandler->moduleExists('history')) {
                $links['comment-new-comments'] = [
                  'title' => '',
                  'url' => Url::fromRoute('<current>'),
                  'attributes' => [
                    'class' => 'hidden',
                    'title' => $this->t('Jump to the first new comment.'),
                    'data-history-node-last-comment-timestamp' => $entity->get($field_name)->last_comment_timestamp,
                    'data-history-node-field-name' => $field_name,
                  ],
                ];
              }
            }
// Optionally filter by entity type and bundle.     if (isset($this->configuration['entity_type'])) {
      $query->condition('fci.entity_type', $this->configuration['entity_type']);

      if (isset($this->configuration['bundle'])) {
        $query->condition('fci.bundle', $this->configuration['bundle']);
      }
    }

    // The Title module fields are not migrated.     if ($this->moduleExists('title')) {
      $title_fields = [
        'title_field',
        'name_field',
        'description_field',
        'subject_field',
      ];
      $query->condition('fc.field_name', $title_fields, 'NOT IN');
    }

    return $query;
  }

  
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;
  }

}
    $default_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
    $entity_cache_contexts = Cache::mergeContexts($default_cache_contexts['url.site']);
    $page_cache_contexts = Cache::mergeContexts($default_cache_contexts['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT]);

    // Cache tags present on every rendered page.     // 'user.permissions' is a required cache context, and responses that vary     // by this cache context when requested by anonymous users automatically     // also get this cache tag, to ensure correct invalidation.     $page_cache_tags = Cache::mergeTags(['http_response', 'rendered']['config:user.role.anonymous']);
    // If the block module is used, the Block page display variant is used,     // which adds the block config entity type's list cache tags.     $page_cache_tags = Cache::mergeTags($page_cache_tags, \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list'] : []);

    $page_cache_tags_referencing_entity = in_array('user.permissions', $this->getAccessCacheContextsForEntity($this->referencingEntity)) ? ['config:user.role.anonymous'] : [];

    $view_cache_tag = [];
    if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) {
      $view_cache_tag = \Drupal::entityTypeManager()->getViewBuilder($entity_type)
        ->getCacheTags();
    }

    $context_metadata = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($entity_cache_contexts);
    $cache_context_tags = $context_metadata->getCacheTags();

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

    $t_args = ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()];
    $this->logger('language')->notice('The %language (%langcode) language has been created.', $t_args);
    $this->messenger()->addStatus($this->t('The language %language has been created and can now be used.', $t_args));

    if ($this->moduleHandler->moduleExists('block')) {
      // Tell the user they have the option to add a language switcher block       // to their theme so they can switch between the languages.       $this->messenger()->addStatus($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href=":block-admin">block administration page</a>.', [':block-admin' => Url::fromRoute('block.admin_display')->toString()]));
    }
    $form_state->setRedirectUrl($this->entity->toUrl('collection'));
  }

  /** * {@inheritdoc} */
  public function actions(array $form, FormStateInterface $form_state) {
    

  public function setSearchManager(PluginManagerInterface $search_manager = NULL) {
    $this->searchManager = $search_manager;
  }

  /** * {@inheritdoc} */
  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();
    if ($this->searchManager && $this->searchManager->hasDefinition('help_search') && $this->moduleHandler->moduleExists('help_topics')) {
      // Rebuild the index on cache clear so that new help topics are indexed       // and any changes due to help topics edits or translation changes are       // picked up.       $help_search = $this->searchManager->createInstance('help_search');
      $help_search->markForReindex();
    }
  }

}
$this->drupalLogin($user);
    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->fieldDisabled('uninstall[dblog]');
    $this->getSession()->getPage()->checkField('uninstall[ban]');
    $this->click('#edit-submit');
    // Click the confirm button.     $this->click('#edit-submit');
    $this->assertSession()->responseContains('The selected modules have been uninstalled.');
    // We've uninstalled a module therefore we need to rebuild the container in     // the test runner.     $this->rebuildContainer();
    $this->assertFalse($this->container->get('module_handler')->moduleExists('ban'));
    try {
      $this->container->get('module_installer')->uninstall(['dblog']);
      $this->fail('Uninstalled dblog module.');
    }
    catch (ModuleUninstallValidatorException $e) {
      $this->assertStringContainsString('The Testing install profile dependencies module is required', $e->getMessage());
    }
  }

}

  public function testInstalled() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);

    $database = Database::getConnection();
    $module = $database->getProvider();
    $module_handler = \Drupal::service('module_handler');

    // Ensure the update module is not installed.     $this->assertFalse($module_handler->moduleExists('update'), 'The Update module is not installed.');

    // Assert that the module that is providing the database driver has been     // installed.     $this->assertTrue($module_handler->moduleExists($module));

    // The module that is providing the database driver should be uninstallable.     try {
      $this->container->get('module_installer')->uninstall([$module]);
      $this->fail("Uninstalled $module module.");
    }
    catch (ModuleUninstallValidatorException $e) {
      
// Purge field data now to allow comment module to be uninstalled once the     // field has been deleted.     field_purge_batch(10);

    // Uninstall the comment module.     $edit = [];
    $edit['uninstall[comment]'] = TRUE;
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    $this->submitForm([], 'Uninstall');
    $this->rebuildContainer();
    $this->assertFalse($this->container->get('module_handler')->moduleExists('comment'), 'Comment module uninstalled.');

    // Install core content type module (book).     $edit = [];
    $edit['modules[book][enable]'] = 'book';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');

    // Now install the comment module.     $edit = [];
    $edit['modules[comment][enable]'] = 'comment';
    $this->drupalGet('admin/modules');
    
$this->rebuildContainer();
    // Verify site name has changed.     $this->assertSame($new_site_name$this->config('system.site')->get('name'));

    // Verify that new config entity exists.     $this->assertSame($original_dynamic_data$this->config($dynamic_name)->get());

    // Verify the cache got cleared.     $this->assertTrue(isset($GLOBALS['hook_cache_flush']));

    $this->rebuildContainer();
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('ban'), 'Ban module installed during import.');
    $this->assertTrue(\Drupal::database()->schema()->tableExists('ban_ip'), 'The database table ban_ip exists.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('automated_cron'), 'Automated Cron module installed during import.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('options'), 'Options module installed during import.');
    $this->assertTrue(\Drupal::moduleHandler()->moduleExists('text'), 'Text module installed during import.');
    $this->assertTrue(\Drupal::service('theme_handler')->themeExists('olivero'), 'Olivero theme installed during import.');

    // Ensure installations and uninstallation occur as expected.     $installed = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_installed', []);
    $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
    $expected = ['automated_cron', 'ban', 'text', 'options'];
    $this->assertSame($expected$installed, 'Automated Cron, Ban, Text and Options modules installed in the correct order.');
    

function hook_config_translation_info(&$info) {
  $entity_type_manager = \Drupal::entityTypeManager();
  $route_provider = \Drupal::service('router.route_provider');

  // If field UI is not enabled, the base routes of the type   // "entity.field_config.{$entity_type}_field_edit_form" are not defined.   if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
    // Add fields entity mappers to all fieldable entity types defined.     foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
      $base_route = NULL;
      try {
        $base_route = $route_provider->getRouteByName('entity.field_config.' . $entity_type_id . '_field_edit_form');
      }
      catch (RouteNotFoundException $e) {
        // Ignore non-existent routes.       }

      // Make sure entity type has field UI enabled and has a base route.

  public function buildByExtension($extension) {
    if ($extension === 'core') {
      $path = 'core';
      $extension_type = 'core';
    }
    else {
      if ($this->moduleHandler->moduleExists($extension)) {
        $extension_type = 'module';
      }
      else {
        $extension_type = 'theme';
      }
      $path = $this->extensionPathResolver->getPath($extension_type$extension);
    }

    $libraries = $this->parseLibraryInfo($extension$path);
    $libraries = $this->applyLibrariesOverride($libraries$extension);

    
/** * Provides a delete form for content menu links. * * @internal */
class MenuLinkContentDeleteForm extends ContentEntityDeleteForm {

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    if ($this->moduleHandler->moduleExists('menu_ui')) {
      return new Url('entity.menu.edit_form', ['menu' => $this->entity->getMenuName()]);
    }
    return $this->entity->toUrl();
  }

  /** * {@inheritdoc} */
  protected function getRedirectUrl() {
    return $this->getCancelUrl();
  }

  
// Get Field API field values.     foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('taxonomy_term', $field_name$tid, NULL, $field_language));
    }

    // If the term name or term description were replaced by real fields using     // the Drupal 7 Title module, use the fields value instead of the term name     // or term description.     if ($this->moduleExists('title')) {
      $name_field = $row->getSourceProperty('name_field');
      if (isset($name_field[0]['value'])) {
        $row->setSourceProperty('name', $name_field[0]['value']);
      }
      $description_field = $row->getSourceProperty('description_field');
      if (isset($description_field[0]['value'])) {
        $row->setSourceProperty('description', $description_field[0]['value']);
      }
      if (isset($description_field[0]['format'])) {
        $row->setSourceProperty('format', $description_field[0]['format']);
      }
    }
'teaser',
        'log',
        'timestamp',
        'format',
        'vid',
      ]);
    $query->addField('n', 'uid', 'node_uid');
    $query->addField('nr', 'uid', 'revision_uid');

    // If the content_translation module is enabled, get the source langcode     // to fill the content_translation_source field.     if ($this->moduleHandler->moduleExists('content_translation')) {
      $query->leftJoin('node', 'nt', '[n].[tnid] = [nt].[nid]');
      $query->addField('nt', 'language', 'source_langcode');
    }

    if (isset($this->configuration['node_type'])) {
      $query->condition('n.type', (array) $this->configuration['node_type'], 'IN');
    }

    return $query;
  }

  
Home | Imprint | This part of the site doesn't use cookies.