コード例 #1
0
ファイル: LanguageBlock.php プロジェクト: sarahwillem/OD8
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $build = array();
     $route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>';
     $type = $this->getDerivativeId();
     $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
     if (isset($links->links)) {
         $build = array('#theme' => 'links__language_block', '#links' => $links->links, '#attributes' => array('class' => array("language-switcher-{$links->method_id}")), '#set_active_class' => TRUE);
     }
     return $build;
 }
コード例 #2
0
 /**
  * Sets the 'is-active' class on links.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The response event.
  */
 public function onResponse(FilterResponseEvent $event)
 {
     // Only care about HTML responses.
     if (stripos($event->getResponse()->headers->get('Content-Type'), 'text/html') === FALSE) {
         return;
     }
     // For authenticated users, the 'is-active' class is set in JavaScript.
     // @see system_page_attachments()
     if ($this->currentUser->isAuthenticated()) {
         return;
     }
     $response = $event->getResponse();
     $response->setContent(static::setLinkActiveClass($response->getContent(), ltrim($this->currentPath->getPath(), '/'), $this->pathMatcher->isFrontPage(), $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), $event->getRequest()->query->all()));
 }