Same name and namespace in other branches
  1. 8.x-2.x src/ExifContent.php \Drupal\exif\ExifContent::getFileUriAndLanguage() 1 comment

Retrieve the URI and Language of an image.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to look for.

string $field_image_name: The field name containing the image.

Return value

array|bool Array with uri and language for each images in or FALSE if the entity type is not known.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

1 call to ExifContent::getFileUriAndLanguage()
ExifContent::getImageFieldsMetadata in src/ExifContent.php
List fields that contains exif metadata.

File

src/ExifContent.php, line 339

Class

ExifContent
Class ExifContent make link between drupal content and file content.

Namespace

Drupal\exif

Code

private function getFileUriAndLanguage(FieldableEntityInterface $entity, $field_image_name) {
    $result = FALSE;
    if ($entity->getEntityTypeId() == 'node' || $entity->getEntityTypeId() == 'media') {
        $image_field_instance = $entity->get($field_image_name);
        if ($image_field_instance instanceof FileFieldItemList) {
            $nbImages = count($image_field_instance->getValue());
            $result = [];
            for ($i = 0; $i < $nbImages; $i++) {
                $result[$i] = [];
                $tmp = $image_field_instance->get($i)->entity;
                $result[$i]['uri'] = $tmp->uri[0];
                $result[$i]['language'] = $tmp->language();
            }
        }
    }
    else {
        if ($entity->getEntityTypeId() == 'file') {
            $result = [];
            $result[0] = [];
            $result[0]['uri'] = $entity->uri;
            $result[0]['language'] = $entity->language();
        }
    }
    return $result;
}