You are here

public function PanelizerFieldPanelsStorage::access in Panelizer 8.3

Same name and namespace in other branches
  1. 8.5 src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php \Drupal\panelizer\Plugin\PanelsStorage\PanelizerFieldPanelsStorage::access()
  2. 8.4 src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php \Drupal\panelizer\Plugin\PanelsStorage\PanelizerFieldPanelsStorage::access()

File

src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php, line 162

Class

PanelizerFieldPanelsStorage
Panels storage service that stores Panels displays in the Panelizer field.

Namespace

Drupal\panelizer\Plugin\PanelsStorage

Code

public function access($id, $op, AccountInterface $account) {
  if ($entity = $this
    ->loadEntity($id)) {
    $access = AccessResult::neutral()
      ->addCacheableDependency($account);

    // We do not support "create", as this method's interface dictates,
    // because we work with existing entities here.
    $entity_operations = [
      'read' => 'view',
      'update' => 'update',
      'delete' => 'delete',
      'change layout' => 'update',
    ];

    // Do not add entity cacheability metadata to the forbidden result,
    // because it depends on the Panels operation, and not on the entity.
    $access
      ->orIf(isset($entity_operations[$op]) ? $entity
      ->access($entity_operations[$op], $account, TRUE) : AccessResult::forbidden());
    if (!$access
      ->isForbidden() && $entity instanceof FieldableEntityInterface) {
      list(, , $view_mode) = explode(':', $id);
      if ($op == 'change layout') {
        if ($this->panelizer
          ->hasEntityPermission('change layout', $entity, $view_mode, $account)) {
          return $access
            ->orIf(AccessResult::allowed());
        }
      }
      else {
        if ($op == 'read' || $this->panelizer
          ->hasEntityPermission('change content', $entity, $view_mode, $account)) {
          return $access
            ->orIf(AccessResult::allowed());
        }
      }
    }
  }
  return AccessResult::forbidden();
}