public function ImageCaptionStorage::getCaption in Image Field Caption 8
Get a caption from the database for the specified arguments.
Parameters
string $entity_type: The entity type, like 'node' or 'comment'.
string $bundle: The bundle, like 'article' or 'news'.
string $field_name: The field name of the image field, like 'field_image' or 'field_article_image'.
int $entity_id: The entity id.
int $revision_id: The revision id.
string $language: The language key, like 'en' or 'fr'.
int $delta: The delta of the image field.
Return value
array A caption array
- caption: The caption text.
- caption_format: The caption format.
or an empty array, if no value found.
1 call to ImageCaptionStorage::getCaption()
- ImageCaptionStorage::isCaption in src/
ImageCaptionStorage.php - Check if a caption is already defined for the specified arguments.
File
- src/
ImageCaptionStorage.php, line 127 - Contains \Drupal\image_field_caption\ImageCaptionStorage.
Class
- ImageCaptionStorage
- Storage controller class for image captions.
Namespace
Drupal\image_field_captionCode
public function getCaption($entity_type, $bundle, $field_name, $entity_id, $revision_id, $language, $delta) {
$captions =& drupal_static(__FUNCTION__);
$cacheKey = $this
->getCacheKey($entity_type, $entity_id, $revision_id, $language, $field_name, $delta);
if (isset($captions[$cacheKey])) {
$caption = $captions[$cacheKey];
}
elseif ($cached = $this->cacheBackend
->get($cacheKey)) {
$caption = $cached->data;
}
else {
// Query.
$query = $this->database
->select($this->tableData, 'ifc');
$result = $query
->fields('ifc', array(
'caption',
'caption_format',
))
->condition('entity_type', $entity_type, '=')
->condition('bundle', $bundle, '=')
->condition('field_name', $field_name, '=')
->condition('entity_id', $entity_id, '=')
->condition('revision_id', $revision_id, '=')
->condition('language', $language, '=')
->condition('delta', $delta, '=')
->execute()
->fetchAssoc();
// Caption array.
$caption = array();
if (!empty($result)) {
$caption = $result;
}
// Let the cache depends on the entity.
// TODO: Use getCacheTags() to get the default list.
$this->cacheBackend
->set($cacheKey, $caption, Cache::PERMANENT, [
$field_name,
'image_field_caption',
]);
}
return $caption;
}