function paragraphs_field_get_entity in Paragraphs 7
Gets a paragraphs item entity for a given field item.
Parameters
string $field_name: (optional) If given and there is no entity yet, a new entity object is created for the given item.
Return value
object|bool The entity object or FALSE.
5 calls to paragraphs_field_get_entity()
- paragraphs_field_formatter_view in ./
paragraphs.field_formatter.inc - Implements hook_field_formatter_view().
- paragraphs_field_presave in ./
paragraphs.module - Implements hook_field_presave().
- paragraphs_field_property_get in ./
paragraphs.module - Entity property info getter callback for the paragraph items.
- paragraphs_field_widget_form_build in ./
paragraphs.field_widget.inc - Widget form implementation for paragraphs.
- paragraphs_i18n_field_prepare_translation in modules/
paragraphs_i18n/ paragraphs_i18n.module - Implements hook_field_prepare_translation().
File
- ./
paragraphs.module, line 1144 - Paragraphs hooks and common functions.
Code
function paragraphs_field_get_entity(&$item, $bundle = NULL, $field_name = NULL) {
if (isset($item['entity'])) {
return $item['entity'];
}
elseif (isset($item['value'])) {
// By default always load the default revision, so caches get used.
$entity = paragraphs_item_load($item['value']);
if ($entity && $entity->revision_id != $item['revision_id']) {
// A non-default revision is a referenced, so load this one.
$entity = paragraphs_item_revision_load($item['revision_id']);
}
return $entity;
}
elseif (!isset($item['entity']) && isset($bundle) && isset($field_name)) {
$item['entity'] = entity_create('paragraphs_item', array(
'bundle' => $bundle,
'field_name' => $field_name,
));
return $item['entity'];
}
return FALSE;
}