function paragraphs_field_property_set in Paragraphs 7
Entity property info setter callback for the paragraph items.
Like entity_metadata_field_property_set(), but supports setting items with revision identifiers.
1 string reference to 'paragraphs_field_property_set'
- paragraphs_entity_metadata_property_callback in ./
paragraphs.module - Callback for generating entity metadata property info for a field instance.
File
- ./
paragraphs.module, line 1104 - Paragraphs hooks and common functions.
Code
function paragraphs_field_property_set($entity, $name, $value, $langcode, $entity_type) {
$field = field_info_field($name);
$columns = array_keys($field['columns']);
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode);
$values = $field['cardinality'] == 1 ? array(
$value,
) : (array) $value;
$items = array();
foreach ($values as $delta => $value) {
if (isset($value)) {
if ($value instanceof ParagraphsItemEntity) {
$items[$delta][$columns[0]] = $value->item_id;
$items[$delta][$columns[1]] = $value->revision_id;
}
elseif (is_array($value) && isset($value['value']) && isset($value['revision_id'])) {
$items[$delta][$columns[0]] = $value['value'];
$items[$delta][$columns[1]] = $value['revision_id'];
}
else {
$item = paragraphs_item_load($value);
$items[$delta][$columns[0]] = $item->item_id;
$items[$delta][$columns[1]] = $item->revision_id;
}
}
}
$entity->{$name}[$langcode] = $items;
// Empty the static field language cache, so the field system picks up any
// possible new languages.
drupal_static_reset('field_language');
}