You are here

function ctools_context_get_defaults in Chaos Tool Suite (ctools) 7

Get the defaults for a new instance of a context plugin.

Parameters

$plugin_definition: The metadata definition of the plugin from ctools_get_plugins().

$object: The object the context plugin will be added to.

$type: The type of context plugin. i.e, context, requiredcontext, relationship

1 call to ctools_context_get_defaults()
ctools_context_ajax_item_add in includes/context-admin.inc
Ajax entry point to add an context

File

includes/context-admin.inc, line 645
includes/common-context.inc Provide API for adding contexts for modules that embed displays.

Code

function ctools_context_get_defaults($plugin_definition, $object, $type) {

  // Fetch the potential id of the plugin so we can append
  // title and keyword information for new ones.
  $type_info = ctools_context_info($type);
  $id = ctools_context_next_id($object->{$type_info['key']}, $plugin_definition['name']);
  $conf = array(
    'identifier' => $plugin_definition['title'] . ($id > 1 ? ' ' . $id : ''),
    'keyword' => ctools_get_keyword($object, $plugin_definition['keyword']),
    'name' => $plugin_definition['name'],
  );
  if (isset($plugin_definition['defaults'])) {
    $defaults = $plugin_definition['defaults'];
  }
  elseif (isset($subtype['defaults'])) {
    $defaults = $subtype['defaults'];
  }
  if (isset($defaults)) {
    if (is_string($defaults) && function_exists($defaults)) {
      if ($settings = $defaults($plugin_definition)) {
        $conf += $settings;
      }
    }
    elseif (is_array($defaults)) {
      $conf += $defaults;
    }
  }
  return $conf;
}