protected function handleIndividualValue($entity_type, $field_type, $field_name, &$value, $delta) { if (!is_array($value)) { return; } if (!array_key_exists('fid', $value)) { throw new ImageCropFieldHandlerException('The field ' . $field_name . ' does not have a file ID.'); } $entity = Entity::load($value['fid'], 'file'); if (!$entity) { throw new FileReferenceHandlerException('The field ' . $field_name . ' has no value.'); } $value['fid'] = self::createReferenceDefinition($entity); $this->addDependency($entity); // Get the original image and store it. $source_file = _imagefield_crop_file_to_crop($value['fid']); if (!$source_file) { throw new ImageCropFieldHandlerException('The field ' . $field_name . ' does not have a valid source file ID.'); } $source_file_entity = Entity::load($source_file->fid, 'file'); if (!$source_file_entity) { throw new ImageCropFieldHandlerException('The field ' . $field_name . ' has no source image.'); } $value['source_fid'] = self::createReferenceDefinition($source_file_entity); $this->addDependency($source_file_entity); // Handle the UID now. if (array_key_exists('uid', $value)) { $entity = Entity::load($value['uid'], 'user'); if (!$entity) { throw new FileReferenceHandlerException('The field ' . $field_name . ' is associated with a user that doesn\'t exist.'); } $value['uid'] = self::createReferenceDefinition($entity); $this->addDependency($entity); } // Make sure the dimensions of the cropbox are always set. if (isset($this->entity->definition->{$field_name})) { $original_entity_definition_language = reset($this->entity->definition->{$field_name}); // First language. if (array_key_exists($delta, $original_entity_definition_language)) { $original_entity_definition = $original_entity_definition_language[$delta]; if (!array_key_exists('cropbox_x', $value)) { $value['cropbox_x'] = array_key_exists('cropbox_x', $original_entity_definition) ? $original_entity_definition['cropbox_x'] : 0; } if (!array_key_exists('cropbox_y', $value)) { $value['cropbox_y'] = array_key_exists('cropbox_y', $original_entity_definition) ? $original_entity_definition['cropbox_y'] : 0; } if (!array_key_exists('cropbox_width', $value)) { $value['cropbox_width'] = array_key_exists('cropbox_width', $original_entity_definition) ? $original_entity_definition['cropbox_width'] : 0; } if (!array_key_exists('cropbox_height', $value)) { $value['cropbox_height'] = array_key_exists('cropbox_height', $original_entity_definition) ? $original_entity_definition['cropbox_height'] : 0; } } } }
// Load gallery of this image. $gallery = new EntityFieldQuery(); $gallery = $gallery->entityCondition('entity_type', 'node')->fieldCondition('field_pictures', 'value', $variables['items'][0]['#entity']->item_id)->range(0, 1)->execute(); $gallery_nids = array_keys($gallery['node']); $gallery = node_load($gallery_nids[0]); ?> <div class="<?php print $classes; ?> "<?php print $attributes; ?> ><?php foreach ($items as $delta => $item) { $file = _imagefield_crop_file_to_crop($item['#item']['fid']); $orig_file_url = file_create_url($file->uri); $colorbox_file_url = image_style_url('1024x', $file->uri); $thumb_file_url = file_create_url($item['#item']['uri']); $id = 'cb-' . $item['#item']['fid']; // Author $author = ''; if (isset($item['#entity']->field_author[LANGUAGE_NONE])) { $author = $item['#entity']->field_author[LANGUAGE_NONE][0]['value']; } if (empty($author)) { $author = $gallery->field_author[LANGUAGE_NONE][0]['value']; } if (!empty($author)) { $author = ' | ' . $author; }