isFrontPage example


  public function testOnlyHtml() {
    $session = new AnonymousUserSession();
    $language_manager = new LanguageManager(new LanguageDefault([]));
    $request_stack = new RequestStack();
    $request_stack->push(new Request());
    $current_path_stack = new CurrentPathStack($request_stack);

    // Make sure path matcher isn't called and we didn't get to the link logic.     $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()->shouldNotBeCalled();

    $subscriber = new ActiveLinkResponseFilter(
      $session,
      $current_path_stack,
      $path_matcher->reveal(),
      $language_manager
    );

    // A link that might otherwise be set 'active'.     $content = '<a data-drupal-link-system-path="other-page">Other page</a>';

    
$registry->setThemeManager(\Drupal::theme());
    $this->assertEquals('value', $registry->get()['theme_test_template_test']['variables']['additional']);
  }

  /** * Tests front node theme suggestion generation. */
  public function testThemeSuggestions() {
    // Mock the current page as the front page.     /** @var \Drupal\Core\Path\PathMatcherInterface $path_matcher */
    $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()->willReturn(TRUE);
    $this->container->set('path.matcher', $path_matcher->reveal());
    /** @var \Drupal\Core\Path\CurrentPathStack $path_matcher */
    $path_current = $this->prophesize(CurrentPathStack::class);
    $path_current->getPath()->willReturn('/node/1');
    $this->container->set('path.current', $path_current->reveal());

    // Check suggestions provided through hook_theme_suggestions_html().     $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_html', [[]]);
    $this->assertSame([
      'html__node',
      'html__node__%',
      
/** * Creates a PathMatcherInterface prophecy. * * @param bool $is_front * Whether the page is the front page. * * @return \Prophecy\Prophecy\ObjectProphecy */
  protected function createPathMatcher($is_front) {
    $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()
      ->willReturn($is_front);

    return $path_matcher;
  }

}
/** * {@inheritdoc} */
  public static function getLabel() {
    return t('Is front page');
  }

  /** * {@inheritdoc} */
  public function getContext() {
    return 'is_front.' . (int) $this->pathMatcher->isFrontPage();
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata() {
    $metadata = new CacheableMetadata();
    $metadata->addCacheTags(['config:system.site']);
    return $metadata;
  }

}
return;
    }

    // If content is FALSE, assume the response does not support the     // setContent() method and skip it, for example,     // \Symfony\Component\HttpFoundation\BinaryFileResponse.     $content = $response->getContent();
    if ($content !== FALSE) {
      $response->setContent(static::setLinkActiveClass(
        $content,
        ltrim($this->currentPath->getPath(), '/'),
        $this->pathMatcher->isFrontPage(),
        $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)
          ->getId(),
        $event->getRequest()->query->all()
      ));
    }
  }

  /** * Sets the "is-active" class on relevant links. * * This is a PHP implementation of the drupal.active-link JavaScript library. * * @param string $html_markup * The HTML markup to update. * @param string $current_path * The system path of the currently active page. * @param bool $is_front * Whether the current page is the front page (which implies the current * path might also be <front>). * @param string $url_language * The language code of the current URL. * @param array $query * The query string for the current URL. * * @return string * The updated HTML markup. * * @todo Once a future version of PHP supports parsing HTML5 properly * (i.e. doesn't fail on * https://www.drupal.org/comment/7938201#comment-7938201) then we can get * rid of this manual parsing and use DOMDocument instead. */

  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $links = [];

    // Add the url.path.parent cache context. This code ignores the last path     // part so the result only depends on the path parents.     $breadcrumb->addCacheContexts(['url.path.parent', 'url.path.is_front']);

    // Do not display a breadcrumb on the frontpage.     if ($this->pathMatcher->isFrontPage()) {
      return $breadcrumb;
    }

    // General path-based breadcrumbs. Use the actual request path, prior to     // resolving path aliases, so the breadcrumb can be defined by simply     // creating a hierarchy of path aliases.     $path = trim($this->context->getPathInfo(), '/');
    $path_elements = explode('/', $path);
    $exclude = [];
    // Don't show a link to the front-page path.     $front = $this->config->get('page.front');
    
Home | Imprint | This part of the site doesn't use cookies.