Update350.php in Lightning Media 8.4
File
modules/lightning_media_video/src/Update/Update350.php
View source
<?php
namespace Drupal\lightning_media_video\Update;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field\Entity\FieldConfig;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Update350 implements ContainerInjectionInterface {
use StringTranslationTrait;
private $mediaTypeStorage;
private $fieldStorage;
public function __construct(EntityStorageInterface $media_type_storage, EntityStorageInterface $field_storage, TranslationInterface $translation = NULL) {
$this->mediaTypeStorage = $media_type_storage;
$this->fieldStorage = $field_storage;
if ($translation) {
$this
->setStringTranslation($translation);
}
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage('media_type'), $container
->get('entity_type.manager')
->getStorage('field_config'), $container
->get('string_translation'));
}
public function removeVideoLibraryFieldTranslatability(StyleInterface $io) {
$field = $this->fieldStorage
->load('media.video.field_media_in_library');
if ($field) {
$this
->processField($io, $field);
}
}
public function removeVideoFileLibraryFieldTranslatability(StyleInterface $io) {
$field = $this->fieldStorage
->load('media.video_file.field_media_in_library');
if ($field) {
$this
->processField($io, $field);
}
}
private function processField(StyleInterface $io, FieldConfig $field) {
$media_type = $field
->getTargetBundle();
$variables = [
'@field' => $field
->label(),
'@media_type' => $this->mediaTypeStorage
->load($media_type)
->label(),
];
$question = (string) $this
->t('Do you want to remove translatability for the @field field of @media_type media?', $variables);
if ($io
->confirm($question)) {
$this->fieldStorage
->save($field
->setTranslatable(FALSE));
}
}
}
Classes
Name |
Description |
Update350 |
Contains optional updates targeting Lightning Media Video 3.5.0. |