You are here

protected function Image::getSettingsFromImageFields in Media Migration 8

Discovers enabled properties based on the image field configurations.

The alt and title properties of an image field always exist, regardless of that they are actually accessible and editable on the entity edit form. This method checks the config of every image field's instance configuration When alt (or title) was enabled for at least one image field, we say that the property should be shown on the destination media entity's edit form.

Parameters

\Drupal\Core\Database\Connection $connection: The database connection of the source Drupal 7 instance.

Return value

array An array of those settings that should be revealed, keyed by the settings key ('alt_field', 'title_field').

1 call to Image::getSettingsFromImageFields()
Image::prepareMediaSourceFieldInstanceRow in src/Plugin/media_migration/file_entity/Image.php

File

src/Plugin/media_migration/file_entity/Image.php, line 249

Class

Image
Image media migration plugin for local image media entities.

Namespace

Drupal\media_migration\Plugin\media_migration\file_entity

Code

protected function getSettingsFromImageFields(Connection $connection) : array {
  $data = [];
  $image_field_names = $this
    ->getImageFieldData($connection);
  foreach ($image_field_names as $image_field_name) {
    $field_instance_config_results = $connection
      ->select('field_config_instance', 'fci')
      ->fields('fci', [
      'data',
    ])
      ->condition('fci.field_name', $image_field_name)
      ->condition('fci.entity_type', 'file', '<>')
      ->execute()
      ->fetchAll();
    foreach ($field_instance_config_results as $field_instance_config_result) {
      $field_config_data = unserialize($field_instance_config_result->data);
      $props = array_map(function (string $property) {
        return "{$property}_field";
      }, array_keys(static::PROPERTY_FIELD_NAME_MAP));
      foreach ($props as $property) {
        if (isset($field_config_data['settings'][$property]) && !empty($field_config_data['settings'][$property])) {
          $data[$property] = TRUE;
        }
      }
      if (empty(array_diff($props, array_keys($data)))) {
        break 2;
      }
    }
  }
  return $data;
}