You are here

private function SiteSettingsLoader::addSupplementaryImageData in Site Settings and Labels 8

Add supplementary image data to the site settings.

Parameters

array $data: The existing data.

object $field: The field object.

Return value

array The data with the new supplementary information included.

1 call to SiteSettingsLoader::addSupplementaryImageData()
SiteSettingsLoader::getValues in src/SiteSettingsLoader.php
Get the values from the entity and return in as simple an array possible.

File

src/SiteSettingsLoader.php, line 285

Class

SiteSettingsLoader
Class SiteSettingsLoader.

Namespace

Drupal\site_settings

Code

private function addSupplementaryImageData(array $data, $field) {
  if ($entities = $field
    ->referencedEntities()) {
    if (count($entities) > 1) {

      // If multiple images add data to each.
      foreach ($data as $key => $sub_image_data) {

        /** @var \Drupal\file\FileInterface $entity */
        $entity = $entities[$key];
        $data[$key]['filename'] = $entity
          ->getFilename();
        $data[$key]['uri'] = $entity
          ->getFileUri();
        $data[$key]['mime_type'] = $entity
          ->getMimeType();
        $data[$key]['size'] = $entity
          ->getSize();
        $data[$key]['is_permanent'] = $entity
          ->isPermanent();
      }
    }
    else {

      // Add the entity to the image.

      /** @var \Drupal\file\FileInterface $entity */
      $entity = reset($entities);
      $data['filename'] = $entity
        ->getFilename();
      $data['uri'] = $entity
        ->getFileUri();
      $data['mime_type'] = $entity
        ->getMimeType();
      $data['size'] = $entity
        ->getSize();
      $data['is_permanent'] = $entity
        ->isPermanent();
    }
  }
  return $data;
}