You are here

protected function MenuTreeResource::checkAccess in REST Menu Tree 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/rest/resource/MenuTreeResource.php \Drupal\rest_menu_tree\Plugin\rest\resource\MenuTreeResource::checkAccess()

Check Access.

Remove items the user does not have access to from the response.

1 call to MenuTreeResource::checkAccess()
MenuTreeResource::get in src/Plugin/rest/resource/MenuTreeResource.php

File

src/Plugin/rest/resource/MenuTreeResource.php, line 158

Class

MenuTreeResource
Provides a resource to get view modes by entity and bundle.

Namespace

Drupal\rest_menu_tree\Plugin\rest\resource

Code

protected function checkAccess(array &$data) {
  foreach ($data as $key => $value) {

    // Use the menu links' access result.
    if ($value->access instanceof AccessResultInterface) {
      if (!$value->access
        ->isAllowed()) {
        unset($data[$key]);
        continue;
      }
    }
    elseif (!$value->link
      ->isEnabled()) {
      unset($data[$key]);
      continue;
    }
    if ($value->subtree) {
      $this
        ->checkAccess($value->subtree);
    }
  }
}