You are here

protected function MenuItemRoleAccessLinkTreeManipulator::getOverridingParent in Menu Item Role Access 8.2

Same name and namespace in other branches
  1. 8 src/MenuItemRoleAccessLinkTreeManipulator.php \Drupal\menu_item_role_access\MenuItemRoleAccessLinkTreeManipulator::getOverridingParent()

Get the first parent that overrides the childrens' settings.

This method gets the parent that has the 'Override children' option enabled. If none was found the input is returned for ease of use. It goes one level up each time and stops at the first match found. This allows for a children to overrule their parent.

Parameters

\Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_item: The original menu link item.

Return value

\Drupal\menu_link_content\Entity\MenuLinkContent The menu link item whose access rules to use.

1 call to MenuItemRoleAccessLinkTreeManipulator::getOverridingParent()
MenuItemRoleAccessLinkTreeManipulator::menuLinkCheckAccess in src/MenuItemRoleAccessLinkTreeManipulator.php
Checks access for one menu link instance.

File

src/MenuItemRoleAccessLinkTreeManipulator.php, line 121

Class

MenuItemRoleAccessLinkTreeManipulator
Defines the access control handler for the menu item.

Namespace

Drupal\menu_item_role_access

Code

protected function getOverridingParent(MenuLinkContent $menu_link_item) {

  // We want the parent overriding permission to overrule the menu-item roles.
  $parent_id = $menu_link_item
    ->getParentId();
  if (!empty($parent_id)) {

    // For now assume loadByUuid() always returns something and not NULL.
    // Make sure we have check parent items enabled.
    $inherit_parent_access = $this->configManager
      ->get('menu_item_role_access.config')
      ->get('inherit_parent_access');
    if ($inherit_parent_access) {
      $parent = $this
        ->loadByUuid($parent_id);
      if ($parent) {
        $override_children_value = $this
          ->getOverrideChildrenValue($parent);

        // The parent has declared to inherit its role settings.
        if ($override_children_value) {
          $menu_link_item = $parent;
        }
        else {

          // The parent did not declare to inherit its role settings.
          // Recursively check grandparents if they have set the option.
          $menu_link_item = $this
            ->getOverridingParent($parent);
        }
      }
    }
  }
  return $menu_link_item;
}