You are here

function ctools_access_add_restrictions in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/context.inc \ctools_access_add_restrictions()

Apply restrictions to contexts based upon the access control configured.

These restrictions allow the UI to not show content that may not be relevant to all types of a particular context.

Parameters

array $settings: Array of keys specifying the settings:

  • 'plugins': the array of plugin metadata info to check. If not set, or not an array, the function returns with no action.
  • 'logic': (optional) either 'and' or 'or', indicating how to combine restrictions. Defaults to 'and'. The 'or' case is not fully implemented and returns with no action if there is more than one plugin.

array $contexts: Array of available contexts.

2 calls to ctools_access_add_restrictions()
ctools_context_handler_set_access_restrictions in includes/context-task-handler.inc
Set any access restrictions on the contexts for a handler.
page_manager_page_access_restrictions in page_manager/plugins/tasks/page.inc
Return a list of arguments used by this task.

File

includes/context.inc, line 2062
Contains code related to the ctools system of 'context'.

Code

function ctools_access_add_restrictions($settings, $contexts) {
  if (empty($settings['plugins']) || !is_array($settings['plugins'])) {
    return;
  }
  if (!isset($settings['logic'])) {
    $settings['logic'] = 'and';
  }

  // We're not going to try to figure out restrictions on the or.
  if ($settings['logic'] === 'or' && count($settings['plugins']) > 1) {
    return;
  }
  foreach ($settings['plugins'] as $test) {
    $plugin = ctools_get_access_plugin($test['name']);

    // $plugin is 'array()' on error.
    if ($plugin && ($function = ctools_plugin_get_function($plugin, 'restrictions'))) {
      $required_context = isset($plugin['required context']) ? $plugin['required context'] : array();
      $context = isset($test['context']) ? $test['context'] : array();
      $contexts = ctools_context_select($contexts, $required_context, $context);
      if ($contexts !== FALSE) {
        $function($test['settings'], $contexts);
      }
    }
  }
}