You are here

public function PanelsPaneController::access in Fieldable Panels Panes (FPP) 7

Custom method to check access to an FPP object for an operation.

Parameters

string $op: The operation to be performed.

object|null $entity: The FPP entity to check.

object $account: The user entity to check.

Return value

bool Whether the user is allowed to perform the requested operation.

File

includes/PanelsPaneController.class.php, line 85
Contains the controller class for the Fieldable Panel Pane entity.

Class

PanelsPaneController
Entity controller class.

Code

public function access($op, $entity = NULL, $account = NULL) {
  if ($op !== 'create' && empty($entity)) {
    return FALSE;
  }

  // The administer permission is a blanket override.
  if (user_access('administer fieldable panels panes')) {
    return TRUE;
  }

  // Trigger hook_fieldable_panels_panes_access().
  // On the first FALSE it will return, otherwise use custom checks below.
  foreach (module_invoke_all('fieldable_panels_panes_access', $op, $entity, $account) as $result) {
    if ($result === FALSE) {
      return $result;
    }
  }
  $bundle = is_string($entity) ? $entity : $entity->bundle;
  if ($op == 'create') {
    return user_access('create fieldable ' . $bundle);
  }
  if ($op == 'view') {
    ctools_include('context');
    return ctools_access($entity->view_access, fieldable_panels_panes_get_base_context($entity));
  }
  if ($op == 'update') {
    ctools_include('context');
    return user_access('edit fieldable ' . $bundle) && ctools_access($entity->edit_access, fieldable_panels_panes_get_base_context($entity));
  }
  if ($op == 'delete') {
    ctools_include('context');
    return user_access('delete fieldable ' . $bundle) && ctools_access($entity->edit_access, fieldable_panels_panes_get_base_context($entity));
  }
  return FALSE;
}