You are here

public function SettingsForm::regenerateThumbnails in Media PDF Thumbnail 8

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsForm.php \Drupal\media_pdf_thumbnail\Form\SettingsForm::regenerateThumbnails()

RegenerateThumbnails.

File

src/Form/SettingsForm.php, line 61

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\media_pdf_thumbnail\Form

Code

public function regenerateThumbnails() {
  $res = Drupal::entityTypeManager()
    ->getStorage('media')
    ->getQuery()
    ->condition('bundle', 'file')
    ->execute();
  if ($res) {
    $medias = Drupal::entityTypeManager()
      ->getStorage('media')
      ->loadMultiple($res);
    if ($medias) {
      foreach ($medias as $media) {
        $media
          ->save();
      }
    }
    Drupal::messenger()
      ->addMessage(t('Images have been regenerated'), 'success');
  }
}