function ctools_context_get_context_from_relationship

Return a context from a relationship.

Parameters

array $relationship: The configuration of a relationship. It must contain the following data:

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

ctools_context $source_context: The context this relationship is based upon.

bool $placeholders: If TRUE, placeholders are acceptable.

Return value

ctools_context|null A context object if one can be loaded, otherwise NULL.

See also

ctools_context_get_relevant_relationships()

ctools_context_get_context_from_relationships()

2 calls to ctools_context_get_context_from_relationship()
ctools_context_get_context_from_relationships in includes/context.inc
Fetch all active relationships.
ctools_context_replace_placeholders in includes/context.inc
Replace placeholders with real contexts using data extracted from a form for the purposes of previews.

File

includes/context.inc, line 1340

Code

function ctools_context_get_context_from_relationship($relationship, $source_context, $placeholders = FALSE) {
    ctools_include('plugins');
    $function = ctools_plugin_load_function('ctools', 'relationships', $relationship['name'], 'context');
    if ($function) {
        // Backward compatibility: Merge old style settings into new style:
        if (!empty($relationship['relationship_settings'])) {
            $relationship += $relationship['relationship_settings'];
            unset($relationship['relationship_settings']);
        }
        $context = $function($source_context, $relationship, $placeholders);
        if ($context) {
            $context->identifier = $relationship['identifier'];
            $context->page_title = isset($relationship['title']) ? $relationship['title'] : '';
            $context->keyword = $relationship['keyword'];
            if (!empty($context->empty)) {
                $context->placeholder = array(
                    'type' => 'relationship',
                    'conf' => $relationship,
                );
            }
            return $context;
        }
    }
    return NULL;
}