You are here

function media_expire_post_update_fallback_id in Media Expire 8

Same name and namespace in other branches
  1. 8.2 media_expire.post_update.php \media_expire_post_update_fallback_id()

Update fallback image configuration.

File

./media_expire.post_update.php, line 13
Install file.

Code

function media_expire_post_update_fallback_id(&$sandbox = NULL) {
  $mediaStorage = \Drupal::entityTypeManager()
    ->getStorage('media');
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'media_bundle', function ($bundle) use ($mediaStorage) {

    /** @var \Drupal\media_entity\Entity\MediaBundle $bundle */
    $fallback_media = $bundle
      ->getThirdPartySetting('media_expire', 'fallback_media');
    if (!empty($fallback_media)) {
      if ($media = $mediaStorage
        ->load($fallback_media)) {
        $bundle
          ->setThirdPartySetting('media_expire', 'fallback_media', $media
          ->uuid());
        return TRUE;
      }
    }
  });
}