You are here

public function ctools_export_ui::access in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 plugins/export_ui/ctools_export_ui.class.php \ctools_export_ui::access()

Menu callback to determine if an operation is accessible.

This function enforces a basic access check on the configured perm string, and then additional checks as needed.

Parameters

$op: The 'op' of the menu item, which is defined by 'allowed operations' and embedded into the arguments in the menu item.

$item: If an op that works on an item, then the item object, otherwise NULL.

Return value

TRUE if the current user has access, FALSE if not.

1 call to ctools_export_ui::access()
stylizer_ui::access in stylizer/plugins/export_ui/stylizer_ui.class.php
Menu callback to determine if an operation is accessible.
1 method overrides ctools_export_ui::access()
stylizer_ui::access in stylizer/plugins/export_ui/stylizer_ui.class.php
Menu callback to determine if an operation is accessible.

File

plugins/export_ui/ctools_export_ui.class.php, line 102

Class

ctools_export_ui
Base class for export UI.

Code

public function access($op, $item) {
  if (!user_access($this->plugin['access'])) {
    return FALSE;
  }

  // More fine-grained access control:
  if ($op == 'add' && !user_access($this->plugin['create access'])) {
    return FALSE;
  }

  // More fine-grained access control:
  if (($op == 'revert' || $op == 'delete') && !user_access($this->plugin['delete access'])) {
    return FALSE;
  }

  // If we need to do a token test, do it here.
  if (!empty($this->plugin['allowed operations'][$op]['token']) && (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], $op))) {
    return FALSE;
  }
  switch ($op) {
    case 'import':
      return user_access('use ctools import');
    case 'revert':
      return $item->export_type & EXPORT_IN_DATABASE && $item->export_type & EXPORT_IN_CODE;
    case 'delete':
      return $item->export_type & EXPORT_IN_DATABASE && !($item->export_type & EXPORT_IN_CODE);
    case 'disable':
      return empty($item->disabled);
    case 'enable':
      return !empty($item->disabled);
    default:
      return TRUE;
  }
}