You are here

function ctools_context_get_context_from_argument in Chaos Tool Suite (ctools) 7

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

Get a context from an argument.

Parameters

$argument: The configuration of an argument. It must contain the following data:

  • name: The name of the argument plugin being used.
  • argument_settings: The configuration based upon the plugin forms.
  • identifier: The human readable identifier for this argument, usually defined by the UI.
  • keyword: The keyword used for this argument for substitutions.

$arg: The actual argument received. This is expected to be a string from a URL but this does not have to be the only source of arguments.

$empty: If true, the $arg will not be used to load the context. Instead, an empty placeholder context will be loaded.

Return value

ctools_context A context object if one can be loaded.

5 calls to ctools_context_get_context_from_argument()
ctools_context_get_context_from_arguments in includes/context.inc
Load the contexts for a given list of arguments.
ctools_context_get_placeholders_from_argument in includes/context.inc
Retrieve a list of empty contexts for all arguments.
ctools_context_replace_placeholders in includes/context.inc
Replace placeholders with real contexts using data extracted from a form for the purposes of previews.
page_manager_page_execute in page_manager/plugins/tasks/page.inc
Execute a page task.
_pm_arg_load in page_manager/plugins/tasks/page.inc
Load a context from an argument for a given page task.

File

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

Code

function ctools_context_get_context_from_argument($argument, $arg, $empty = FALSE) {
  ctools_include('plugins');
  if (empty($argument['name'])) {
    return NULL;
  }
  $function = ctools_plugin_load_function('ctools', 'arguments', $argument['name'], 'context');
  if ($function) {

    // Backward compatibility: Merge old style settings into new style:
    if (!empty($argument['settings'])) {
      $argument += $argument['settings'];
      unset($argument['settings']);
    }
    $context = $function($arg, $argument, $empty);
    if (is_object($context)) {
      $context->identifier = $argument['identifier'];
      $context->page_title = isset($argument['title']) ? $argument['title'] : '';
      $context->keyword = $argument['keyword'];
      $context->id = ctools_context_id($argument, 'argument');
      $context->original_argument = $arg;
      if (!empty($context->empty)) {
        $context->placeholder = array(
          'type' => 'argument',
          'conf' => $argument,
        );
      }
    }
    return $context;
  }
}