lightning_media_video.install in Lightning Media 8.2
Contains install and update routines for Lightning Media Video.
File
modules/lightning_media_video/lightning_media_video.installView source
<?php
/**
* @file
* Contains install and update routines for Lightning Media Video.
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\media\Entity\MediaType;
/**
* Installs video_embed_media and updates display settings for videos.
*/
function lightning_media_video_update_8001() {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
$module_installer = \Drupal::service('module_installer');
// VEF will migrate the video media bundle, but not its display configuration.
$module_installer
->install([
'video_embed_media',
]);
// Migrate the form display for the video bundle.
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = EntityFormDisplay::load('media.video.default');
if ($form_display) {
$old_component = $form_display
->getComponent('embed_code');
$form_display
->removeComponent('field_embed_code')
->setComponent('field_media_video_embed_field', [
'type' => 'video_embed_field_textfield',
'weight' => $old_component['weight'],
'settings' => array(),
'third_party_settings' => array(),
])
->save();
}
// Migrate the "live" view displays for the video bundle.
foreach ([
'default',
'embedded',
] as $view_display) {
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
$view_display = EntityViewDisplay::load('media.video.' . $view_display);
if ($view_display) {
$old_component = $form_display
->getComponent('embed_code');
$view_display
->removeComponent('field_embed_code')
->setComponent('field_media_video_embed_field', [
'type' => 'video_embed_field_video',
'weight' => $old_component['weight'],
'label' => $old_component['label'],
'settings' => [
'responsive' => TRUE,
'width' => 854,
'height' => 480,
'autoplay' => TRUE,
],
'third_party_settings' => array(),
])
->save();
}
}
// Reconfigure the video media bundle.
MediaType::load('video')
->set('source_configuration', [
'source_field' => 'field_media_video_embed_field',
])
->save();
// Delete the old embed code field.
FieldConfig::load('media.video.embed_code')
->delete();
// Don't need MEEV anymore!
$module_installer
->uninstall([
'media_entity_embeddable_video',
]);
}
/**
* Creates the media_browser form display.
*/
function lightning_media_video_update_8002() {
Config::forModule('lightning_media_video')
->getEntity('entity_form_display', 'media.video.media_browser')
->save();
}
/**
* Creates the thumbnail display for videos.
*/
function lightning_media_video_update_8003() {
Config::forModule('lightning_media_video')
->getEntity('entity_view_display', 'media.video.thumbnail')
->save();
}
/**
* Implements hook_update_dependencies().
*/
function lightning_media_video_update_dependencies() {
return [
'lightning_media_video' => [
// 8003 depends on the thumbnail view mode, which is created by
// lightning_media 8015.
8003 => [
'lightning_media' => 8015,
],
],
];
}
Functions
Name![]() |
Description |
---|---|
lightning_media_video_update_8001 | Installs video_embed_media and updates display settings for videos. |
lightning_media_video_update_8002 | Creates the media_browser form display. |
lightning_media_video_update_8003 | Creates the thumbnail display for videos. |
lightning_media_video_update_dependencies | Implements hook_update_dependencies(). |