You are here

function media_thumbnails_media_presave in Media Thumbnails 8

Implements hook_ENTITY_TYPE_presave().

File

./media_thumbnails.module, line 28
Plugin manager for media entity thumbnail generation.

Code

function media_thumbnails_media_presave(MediaInterface $entity) {

  /** @var \Drupal\media_thumbnails\Plugin\MediaThumbnailManager $manager */
  $manager = \Drupal::service('plugin.manager.media_thumbnail');
  if ($manager
    ->hasPlugin($entity)) {
    if ($entity
      ->isNew()) {
      $manager
        ->createThumbnail($entity);
    }
    else {
      $manager
        ->updateThumbnail($entity);
    }
  }
}