You are here

protected function UpgradeManager::upgradeBundle in Video Embed Field 8

Upgrade a whole bundle to use video_embed_field.

Parameters

\Drupal\media_entity\Entity\MediaBundle $bundle: The media bundle object.

1 call to UpgradeManager::upgradeBundle()
UpgradeManager::upgrade in modules/video_embed_media/src/UpgradeManager.php
Upgrade the existing media_entity_embedded_video bundles.

File

modules/video_embed_media/src/UpgradeManager.php, line 49

Class

UpgradeManager
Upgrades existing media_entity_embedded_video bundles.

Namespace

Drupal\video_embed_media

Code

protected function upgradeBundle(MediaBundle $bundle) {

  // Create a video embed field on the media bundle.
  VideoEmbedField::createVideoEmbedField($bundle
    ->id());

  // Load and update all of the existing media entities.
  $media_entities = $this->entityQuery
    ->get('media')
    ->condition('bundle', $bundle
    ->id())
    ->execute();
  foreach ($media_entities as $media_entity) {
    $media_entity = Media::load($media_entity);
    $this
      ->upgradeEntity($media_entity, $bundle
      ->getTypeConfiguration());
  }

  // Update the media bundle type.
  $bundle->type = 'video_embed_field';
  $bundle
    ->save();
}