You are here

protected function LanguageSwitcherLinkProcessor::getPageEntity in Language Switcher Extended 8

Retrieves the current page entity.

Return value

\Drupal\Core\Entity\ContentEntityInterface The retrieved entity, or FALSE if none found.

1 call to LanguageSwitcherLinkProcessor::getPageEntity()
LanguageSwitcherLinkProcessor::processUntranslatedLinks in src/LanguageSwitcherLinkProcessor.php
Processes all untranslated language switcher items.

File

src/LanguageSwitcherLinkProcessor.php, line 196

Class

LanguageSwitcherLinkProcessor
Processes the Language Switcher links.

Namespace

Drupal\language_switcher_extended

Code

protected function getPageEntity() {
  $params = $this->currentRouteMatch
    ->getParameters()
    ->all();

  // Iterate through the parameters and search for the first content entity.
  // Use a loop, because the content entity might not be the first parameter,
  // e.g. when using page_manager.
  foreach ($params as $param) {
    if ($param instanceof ContentEntityInterface) {

      // If you find a ContentEntityInterface stop iterating and return it.
      return $param;
    }
  }
  return FALSE;
}