You are here

public function EntityImageStyle::import in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php \Drupal\image\Plugin\migrate\destination\EntityImageStyle::import()

Import the row.

Derived classes must implement import(), to construct one new object (pre-populated) using ID mappings in the Migration.

Parameters

\Drupal\migrate\Row $row: The row object.

array $old_destination_id_values: (optional) The old destination IDs. Defaults to an empty array.

Return value

array|bool An indexed array of destination IDs in the same order as defined in the plugin's getIds() method if the plugin wants to save the IDs to the ID map, TRUE to indicate success without saving IDs to the ID map, or FALSE to indicate a failure.

Overrides EntityConfigBase::import

File

core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php, line 23

Class

EntityImageStyle
Every migration that uses this destination must have an optional dependency on the d6_file migration to ensure it runs first.

Namespace

Drupal\image\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) {
  $effects = [];

  // Need to set the effects property to null on the row before the ImageStyle
  // is created, this prevents improper effect plugin initialization.
  if ($row
    ->getDestinationProperty('effects')) {
    $effects = $row
      ->getDestinationProperty('effects');
    $row
      ->setDestinationProperty('effects', []);
  }

  /** @var \Drupal\image\Entity\ImageStyle $style */
  $style = $this
    ->getEntity($row, $old_destination_id_values);

  // Iterate the effects array so each effect plugin can be initialized.
  // Catch any missing plugin exceptions.
  foreach ($effects as $effect) {
    try {
      $style
        ->addImageEffect($effect);
    } catch (PluginNotFoundException $e) {
      throw new MigrateException($e
        ->getMessage(), 0, $e);
    }
  }
  $style
    ->save();
  return [
    $style
      ->id(),
  ];
}