function MediaDevelGenerate::mediaKill

Same name in other branches
  1. 4.x devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MediaDevelGenerate::mediaKill()

Deletes all media of given media media types.

Parameters

array $values: The input values from the settings form.

Throws

\Drupal\Core\Entity\EntityStorageException Thrown if the media type does not exist.

2 calls to MediaDevelGenerate::mediaKill()
MediaDevelGenerate::batchMediaKill in devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php
Provides a batch version of mediaKill().
MediaDevelGenerate::generateMedia in devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php
Method for creating media when number of elements is less than 50.

File

devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php, line 425

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function mediaKill(array $values) : void {
    $mids = $this->mediaStorage
        ->getQuery()
        ->condition('bundle', $values['media_types'], 'IN')
        ->accessCheck(FALSE)
        ->execute();
    if (!empty($mids)) {
        $media = $this->mediaStorage
            ->loadMultiple($mids);
        $this->mediaStorage
            ->delete($media);
        $this->setMessage($this->t('Deleted %count media items.', [
            '%count' => count($mids),
        ]));
    }
}