You are here

protected function UpgradeManager::upgradeEntity in Video Embed Field 8

Upgrade an individual media entity.

Parameters

\Drupal\media_entity\Entity\Media $media_entity: The media entity.

array $type_configuration: The media type configuration.

1 call to UpgradeManager::upgradeEntity()
UpgradeManager::upgradeBundle in modules/video_embed_media/src/UpgradeManager.php
Upgrade a whole bundle to use video_embed_field.

File

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

Class

UpgradeManager
Upgrades existing media_entity_embedded_video bundles.

Namespace

Drupal\video_embed_media

Code

protected function upgradeEntity(Media $media_entity, $type_configuration) {

  // Copy the existing media bundle field value to the new field value.
  $existing_url_field = $media_entity->{$type_configuration['source_field']}
    ->getValue();
  $existing_url = isset($existing_url_field[0]['uri']) ? $existing_url_field[0]['uri'] : $existing_url_field[0]['value'];
  $media_entity->{VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME} = [
    [
      'value' => $existing_url,
    ],
  ];
  $media_entity
    ->save();
}