You are here

protected function Image::mergePropertyRequiredSettingsFromImageFields in Media Migration 8

Merges alt/title 'required' settings based on image field discovery.

If any image field have alt (or title) set up as optional, we don't let them being required.

Parameters

array $data: The discovered data about alt and title revealment.

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

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

File

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

Class

Image
Image media migration plugin for local image media entities.

Namespace

Drupal\media_migration\Plugin\media_migration\file_entity

Code

protected function mergePropertyRequiredSettingsFromImageFields(array &$data, Connection $connection) : void {
  foreach (static::PROPERTY_FIELD_NAME_MAP as $property => $field_name) {
    $property_field_config_result = $connection
      ->select('field_config_instance', 'fci')
      ->fields('fci', [
      'data',
    ])
      ->condition('fci.field_name', $field_name)
      ->condition('fci.bundle', 'image')
      ->condition('fci.entity_type', 'file')
      ->execute()
      ->fetchAll();
    if (empty($property_field_config_result)) {
      continue;
    }
    assert(count($property_field_config_result) === 1);
    if ($property_field_config_data = unserialize($property_field_config_result[0]->data)) {
      if (isset($property_field_config_data['required'])) {
        $not_set_or_not_required = !isset($data["{$property}_field_required"]) || empty($data["{$property}_field_required"]);
        $data["{$property}_field_required"] = $not_set_or_not_required && !empty($data["{$property}_field"]) && !empty($property_field_config_data['required']);
      }
    }
  }
}