setLinkActiveClass example


  public function testSetLinkActiveClass($html_markup$current_path$is_front$url_language, array $query$expected_html_markup) {
    $this->assertSame($expected_html_markup, ActiveLinkResponseFilter::setLinkActiveClass($html_markup$current_path$is_front$url_language$query));
  }

  /** * Tests ActiveLinkResponseFilter only affects HTML responses. * * @covers ::onResponse */
  public function testOnlyHtml() {
    $session = new AnonymousUserSession();
    $language_manager = new LanguageManager(new LanguageDefault([]));
    $request_stack = new RequestStack();
    
// For authenticated users, the 'is-active' class is set in JavaScript.     // @see system_page_attachments()     if ($this->currentUser->isAuthenticated()) {
      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. */
Home | Imprint | This part of the site doesn't use cookies.