You are here

public function MediaExpireService::getFallbackMedia in Media Expire 8.2

Returns the fallback media item.

Parameters

\Drupal\media\MediaInterface $media: The current media item.

Return value

\Drupal\Core\Entity\EntityInterface|null The fallback media.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

src/MediaExpireService.php, line 88

Class

MediaExpireService
Contains the media unpublish logic.

Namespace

Drupal\media_expire

Code

public function getFallbackMedia(MediaInterface $media) {

  /** @var \Drupal\media\MediaTypeInterface $bundle */
  $bundle = $this->entityTypeManager
    ->getStorage('media_type')
    ->load($media
    ->bundle());
  if ($bundle
    ->getThirdPartySetting('media_expire', 'enable_expiring') && !$media
    ->isPublished()) {
    $fallbackMediaUuid = $bundle
      ->getThirdPartySetting('media_expire', 'fallback_media');
    if ($fallbackMediaUuid && ($media = $this->entityRepository
      ->loadEntityByUuid('media', $fallbackMediaUuid))) {
      return $media;
    }
  }
}