class EntityImageStyle

Same name and namespace in other branches
  1. 11.x core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php \Drupal\image\Plugin\migrate\destination\EntityImageStyle
  2. 10 core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php \Drupal\image\Plugin\migrate\destination\EntityImageStyle
  3. 8.9.x core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php \Drupal\image\Plugin\migrate\destination\EntityImageStyle

Entity image style destination.

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

Plugin annotation


@MigrateDestination(
  id = "entity:image_style"
)

Hierarchy

Expanded class hierarchy of EntityImageStyle

File

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

Namespace

Drupal\image\Plugin\migrate\destination
View source
class EntityImageStyle extends EntityConfigBase {
  
  /**
   * {@inheritdoc}
   */
  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(),
    ];
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.