You are here

protected function Image::getImageAltTitleSettingsFromPropertyFieldContent in Media Migration 8

Discovers the image field settings based on existing property values.

The alt and title properties of an image field always exist, regardless of whether they are actually accessible and editable on the entity edit form or not. This method checks the content of the corresponding alt and title fields. If we find at least a single, non-empty row, we say that the actual 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

true[] An array of those field instance settings that should be revealed, keyed by the settings key ("alt_field", "title_field"). For example, if we have rows for alt, but don't have any data for title, the array returned will be this:

[
  "alt_field" => TRUE,
];
1 call to Image::getImageAltTitleSettingsFromPropertyFieldContent()
Image::prepareMediaSourceFieldInstanceRow in src/Plugin/media_migration/file_entity/Image.php

File

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

Class

Image
Image media migration plugin for local image media entities.

Namespace

Drupal\media_migration\Plugin\media_migration\file_entity

Code

protected function getImageAltTitleSettingsFromPropertyFieldContent(Connection $connection) : array {
  $data = [];
  foreach (static::PROPERTY_FIELD_NAME_MAP as $property => $field_name) {
    if (!$connection
      ->schema()
      ->tableExists("field_data_{$field_name}")) {
      continue;
    }
    $property_values_query = $connection
      ->select("field_data_{$field_name}", $field_name)
      ->fields($field_name)
      ->condition("{$field_name}.{$field_name}_value", '', '<>')
      ->isNotNull("{$field_name}.{$field_name}_value");
    $property_values_present = (int) $property_values_query
      ->countQuery()
      ->execute()
      ->fetchField() > 0;
    if ($property_values_present) {
      $data["{$property}_field"] = TRUE;
    }
  }
  return $data;
}