You are here

protected function DomainMenuLinkTreeManipulators::menuLinkCheckAccess in Domain Menu Access 8

Checks access for one menu link instance.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $instance: The menu link instance.

\Drupal\Core\Language\LanguageInterface $current_language: The current language.

Return value

\Drupal\Core\Access\AccessResultInterface|NULL The access result.

1 call to DomainMenuLinkTreeManipulators::menuLinkCheckAccess()
DomainMenuLinkTreeManipulators::checkDomain in src/Menu/DomainMenuLinkTreeManipulators.php
Performs access checking for menu link content in an optimized way.

File

src/Menu/DomainMenuLinkTreeManipulators.php, line 113

Class

DomainMenuLinkTreeManipulators
Provides a couple of menu link tree manipulators.

Namespace

Drupal\domain_menu_access\Menu

Code

protected function menuLinkCheckAccess(MenuLinkInterface $instance, LanguageInterface $current_language) {

  // Default access.
  $access_result = AccessResult::allowed();

  /** @var MenuLinkContent $entity */
  if ($entity = $this
    ->loadMenuLinkContentEntity($instance)) {
    if ($entity
      ->hasTranslation($current_language
      ->getId())) {
      $entity = $entity
        ->getTranslation($current_language
        ->getId());
    }
    if (!$this
      ->isAvailableOnAllAffiliates($entity)) {
      $domain_access = [];
      foreach ($entity
        ->get(DOMAIN_ACCESS_FIELD)
        ->getValue() as $reference) {
        $domain_access[] = $reference['target_id'];
      }
      $active_domain = $this->domainNegotiator
        ->getActiveDomain();
      if ($active_domain instanceof DomainInterface && !in_array($active_domain
        ->getOriginalId(), $domain_access)) {
        $access_result = AccessResult::forbidden();
      }
    }
  }
  return $access_result
    ->cachePerPermissions();
}