function image_field_caption_field_attach_load in Image Field Caption 7.2
Implements hook_field_attach_load().
File
- ./
image_field_caption.module, line 327 - Provides a caption textarea for image fields.
Code
function image_field_caption_field_attach_load($entity_type, $entities, $age, $options) {
foreach ($entities as $entity) {
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
if (!isset($vid)) {
$vid = $id;
}
$load_current = $age == FIELD_LOAD_CURRENT;
$table = $load_current ? 'field_image_field_caption' : 'field_image_field_caption_revision';
$query = db_select($table, 't')
->fields('t')
->condition('entity_type', $entity_type)
->condition($load_current ? 'entity_id' : 'revision_id', $load_current ? $id : $vid)
->orderBy('delta');
$results = $query
->execute();
foreach ($results as $row) {
$field = field_info_instance($entity_type, $row->field_name, $bundle);
if (!isset($field['settings']['image_field_caption']) || !$field['settings']['image_field_caption']['enabled']) {
continue;
}
$item['image_field_caption']['value'] = $row->caption;
$item['image_field_caption']['format'] = $row->caption_format;
// Add the item to the field values for the entity.
$entities[$row->entity_id]->{$row->field_name}[$row->language][$row->delta]['image_field_caption']['value'] = $row->caption;
$entities[$row->entity_id]->{$row->field_name}[$row->language][$row->delta]['image_field_caption']['format'] = $row->caption_format;
}
}
}