function ctools_entity_from_schema_context

Return a new context based on an existing context.

1 string reference to 'ctools_entity_from_schema_context'
entity_from_schema.inc in plugins/relationships/entity_from_schema.inc
Plugin to provide an relationship handler for an entity from a field.

File

plugins/relationships/entity_from_schema.inc, line 114

Code

function ctools_entity_from_schema_context($context, $conf) {
    $plugin = $conf['name'];
    list($plugin, $plugin_name) = explode(':', $plugin);
    list($this_col, $from_entity, $to_entity) = explode('-', $plugin_name);
    // If unset it wants a generic, unfilled context, which is just NULL.
    $entity_info = entity_get_info($from_entity);
    if (empty($context->data) || !isset($context->data->{$entity_info['entity keys']['id']})) {
        return ctools_context_create_empty('entity:' . $to_entity, NULL);
    }
    if (isset($context->data->{$entity_info['entity keys']['id']})) {
        // Load the entity.
        $id = $context->data->{$entity_info['entity keys']['id']};
        $entity = entity_load($from_entity, array(
            $id,
        ));
        $entity = $entity[$id];
        if (isset($entity->{$this_col})) {
            $to_entity_id = $entity->{$this_col};
            // Send it to ctools.
            return ctools_context_create('entity:' . $to_entity, $to_entity_id);
        }
    }
}