rebuild example

$state = $this->container->get('state');
    // Define the schema and views data variable before enabling the test module.     $state->set('views_test_data_schema', $this->schemaDefinition());
    $state->set('views_test_data_views_data', $this->viewsData());
    $this->container->get('views.views_data')->clear();

    $this->installConfig(['views', 'views_test_config', 'views_test_data']);
    foreach ($this->schemaDefinition() as $table => $schema) {
      $this->installSchema('views_test_data', $table);
    }

    $this->container->get('router.builder')->rebuild();

    // Load the test dataset.     $data_set = $this->dataSet();
    $query = Database::getConnection()->insert('views_test_data')
      ->fields(array_keys($data_set[0]));
    foreach ($data_set as $record) {
      $query->values($record);
    }
    $query->execute();
  }

  
Cache::invalidateTags(['local_task']);
  }

  /** * Perform menu-specific rebuilding. */
  protected function menuLinksRebuild() {
    if ($this->lock->acquire(__FUNCTION__)) {
      try {
        $transaction = $this->connection->startTransaction();
        // Ensure the menu links are up to date.         $this->menuLinkManager->rebuild();
        // Ignore any database replicas temporarily.         $this->replicaKillSwitch->trigger();
      }
      catch (\Exception $e) {
        if (isset($transaction)) {
          $transaction->rollBack();
        }
        Error::logException($this->logger, $e);
      }

      $this->lock->release(__FUNCTION__);
    }
->getEditable('system.theme')
      ->set('admin', 'claro')
      ->set('default', 'stable')
      ->save();
    $theme_handler->refreshInfo();
    // Check that the page has been served with the default theme.     $this->drupalGet('test_page_display_200');
    $this->assertSession()->responseNotContains('core/themes/claro/css/base/elements.css');

    $view = $this->config('views.view.test_page_display');
    $view->set('display.page_3.display_options.use_admin_theme', TRUE)->save();
    $this->container->get('router.builder')->rebuild();

    // Check that the page was served with the administrative theme.     $this->drupalGet('test_page_display_200');
    $this->assertSession()->responseContains('core/themes/claro/css/base/elements.css');
  }

  /** * Tests that we can successfully change a view page display path. * * @param string $path * Path that will be set as the view page display path. * * @internal */
$this->rebuildNeeded = FALSE;

    return TRUE;
  }

  /** * {@inheritdoc} */
  public function rebuildIfNeeded() {
    if ($this->rebuildNeeded) {
      return $this->rebuild();
    }
    return FALSE;
  }

  /** * {@inheritdoc} */
  public function destruct() {
    // Rebuild routes only once at the end of the request lifecycle to not     // trigger multiple rebuilds and also make the page more responsive for the     // user.
/** * Loads the real route provider from the container and rebuilds the router. * * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface * The route provider. */
  protected function lazyLoadItself() {
    if (!isset($this->service)) {
      $container = \Drupal::getContainer();
      $this->service = $container->get('test.router.route_provider');
      $container->get('router.builder')->rebuild();
    }

    return $this->service;
  }

  /** * {@inheritdoc} */
  public function getRouteCollectionForRequest(Request $request) {
    return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
  }

  


    // Set the node search as default.     $this->setDefaultThroughUi('node_search');

    // Test with all search plugins enabled. When you go to the search     // page or run search, all plugins should be shown.     foreach ($entities as $entity) {
      $entity->enable()->save();
    }

    \Drupal::service('router.builder')->rebuild();

    $paths = [
      ['path' => 'search/node', 'options' => ['query' => ['keys' => 'pizza']]],
      ['path' => 'search/node', 'options' => []],
    ];

    foreach ($paths as $item) {
      $this->drupalGet($item['path']$item['options']);
      foreach ($plugins as $entity_id) {
        $path = 'search/' . $entities[$entity_id]->getPath();
        $label = $entities[$entity_id]->label();
        
// Enable both language_interface and language_content language negotiation.     \Drupal::getContainer()->get('language_negotiator')->updateConfiguration([
      'language_interface',
      'language_content',
    ]);

    // Set the preferred language of the user for admin pages to English.     $user->set('preferred_admin_langcode', 'en')->save();

    // Make sure node edit pages are administration pages.     $this->config('node.settings')->set('use_admin_theme', '1')->save();
    $this->container->get('router.builder')->rebuild();

    // Place a Block with a translatable string on the page.     $this->placeBlock('system_powered_by_block', ['region' => 'content']);

    // Load the Spanish Node page once, to register the translatable string.     $this->drupalGet('/es/node/1');

    // Translate the Powered by string.     /** @var \Drupal\locale\StringStorageInterface $string_storage */
    $string_storage = \Drupal::getContainer()->get('locale.storage');
    $source = $string_storage->findString(['source' => 'Powered by <a href=":poweredby">Drupal</a>']);
    

        public function setRebuildNeeded()
        {
            return $this->lazyLoadItself()->setRebuildNeeded();
        }

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

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

        /** * {@inheritdoc} */
$this->routeBuilder = $route_builder;
  }

  /** * Gets the real route provider service and rebuilds the router id necessary. * * @return \Drupal\Core\Routing\RouteProviderInterface * The route provider service. */
  protected function getRouteProvider() {
    if (!$this->rebuilt && !$this->rebuilding) {
      $this->routeBuilder->rebuild();
    }
    return $this->routeProvider;
  }

  /** * {@inheritdoc} */
  public function getRouteCollectionForRequest(Request $request) {
    return $this->getRouteProvider()->getRouteCollectionForRequest($request);
  }

  
    $this->drupalGet('test-disabled-display-2');
    $this->assertSession()->elementTextEquals('xpath', '//h1[@class="page-title"]', 'test_disabled_display');

    // Disable each disabled display and save the view.     foreach ($display_ids as $display_id) {
      $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', FALSE);
      $view->save();
      $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
      $this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled');
    }

    \Drupal::service('router.builder')->rebuild();

    // Check that the page_1 display still works.     $this->drupalGet('test-disabled-display');
    $this->assertSession()->statusCodeEquals(200);

    // Check that the page_2 display is now disabled again.     $this->drupalGet('test-disabled-display-2');
    $this->assertSession()->statusCodeEquals(404);
  }

}
// Create a user that can.     $this->userCanViewProfiles = $this->drupalCreateUser([
      'access user profiles',
    ]);

    $this->grantPermissions(Role::load(RoleInterface::ANONYMOUS_ID)[
      'access user profiles',
      'administer taxonomy',
    ]);

    \Drupal::service('router.builder')->rebuild();
  }

  /** * Performs a HTTP request. Wraps the Guzzle HTTP client. * * Why wrap the Guzzle HTTP client? Because any error response is returned via * an exception, which would make the tests unnecessarily complex to read. * * @param string $method * HTTP method. * @param \Drupal\Core\Url $url * URL to request. * @param array $request_options * Request options to apply. * * @return \Psr\Http\Message\ResponseInterface * The request response. * * @throws \GuzzleHttp\Exception\GuzzleException * * @see \GuzzleHttp\ClientInterface::request */
if (!InstallerKernel::installationAttempted()) {
        // If the container was rebuilt during hook_install() it might not have         // the 'router.route_provider.old' service.         if (\Drupal::hasService('router.route_provider.old')) {
          \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
        }
        if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
          // Rebuild routes after installing module. This is done here on top of           // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on           // fastCGI which executes ::destruct() after the module installation           // page was sent already.           \Drupal::service('router.builder')->rebuild();
        }
      }

      $this->moduleHandler->invokeAll('modules_installed', [$modules_installed$sync_status]);
    }

    return TRUE;
  }

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

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    \Drupal::configFactory()
      ->getEditable('media.settings')
      ->set('standalone_url', TRUE)
      ->save(TRUE);
    $this->container->get('router.builder')->rebuild();
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    // Create a media type.     $mediaType = $this->createMediaType('test');

    // Create a media item.     $media = Media::create([
      

  public function rebuild() {
    $definitions = $this->getDefinitions();
    // Apply overrides from config.     $overrides = $this->overrides->loadMultipleOverrides(array_keys($definitions));
    foreach ($overrides as $id => $changes) {
      if (!empty($definitions[$id])) {
        $definitions[$id] = $changes + $definitions[$id];
      }
    }
    $this->treeStorage->rebuild($definitions);
  }

  /** * {@inheritdoc} */
  public function getDefinition($plugin_id$exception_on_invalid = TRUE) {
    $definition = $this->treeStorage->load($plugin_id);
    if (empty($definition) && $exception_on_invalid) {
      throw new PluginNotFoundException($plugin_id);
    }
    return $definition;
  }
$this->submitForm($form_data, 'Save');
    $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests that the "add to shortcut" and "remove from shortcut" links work. */
  public function testShortcutQuickLink() {
    \Drupal::service('theme_installer')->install(['claro']);
    $this->config('system.theme')->set('admin', 'claro')->save();
    $this->config('node.settings')->set('use_admin_theme', '1')->save();
    $this->container->get('router.builder')->rebuild();

    $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/config/system/cron');

    // Test the "Add to shortcuts" link.     $this->clickLink('Add to Default shortcuts');
    $this->assertSession()->pageTextContains('Added a shortcut for Cron.');
    $this->assertSession()->linkExists('Cron', 0, 'Shortcut link found on page');

    $this->drupalGet('admin/structure');
    $this->assertSession()->linkExists('Cron', 0, 'Shortcut link found on different page');

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