function field_collection_field_collection_from_field_context in Field collection 7
Return a new field collection context based on an existing context.
1 string reference to 'field_collection_field_collection_from_field_context'
- field_collection_from_field.inc in ctools/
relationships/ field_collection_from_field.inc - Plugin to provide a relationship handler for a field collection field.
File
- ctools/
relationships/ field_collection_from_field.inc, line 72 - Plugin to provide a relationship handler for a field collection field.
Code
function field_collection_field_collection_from_field_context($context, $conf) {
$plugin_info = ctools_get_relationship($conf['name']);
$delta = (int) $conf['delta'];
$entity = $context->data;
if (isset($entity->{$plugin_info['field_name']})) {
$items = field_get_items($plugin_info['entity_type'], $entity, $plugin_info['field_name']);
// Use negative delta to get item from the end.
if ($delta < 0) {
// Add negative pseudo-delta to total amount of items to get the real
// delta. Example (field_collection with 5 elements): count() == 5:
// 5 + -1 = 4, which would be the last element in this example.
$delta = count($items) + $delta;
}
if (!empty($items) && isset($items[$delta]['value'])) {
return ctools_context_create('entity:field_collection_item', $items[$delta]['value']);
}
}
return ctools_context_create_empty('entity:field_collection_item', NULL);
}