You are here

final class Update350 in Lightning Media 8.3

Same name in this branch
  1. 8.3 modules/lightning_media_audio/src/Update/Update350.php \Drupal\lightning_media_audio\Update\Update350
  2. 8.3 modules/lightning_media_video/src/Update/Update350.php \Drupal\lightning_media_video\Update\Update350
Same name and namespace in other branches
  1. 8.4 modules/lightning_media_video/src/Update/Update350.php \Drupal\lightning_media_video\Update\Update350

Contains optional updates targeting Lightning Media Video 3.5.0.

Plugin annotation

@Update("3.5.0");

Hierarchy

Expanded class hierarchy of Update350

1 file declares its use of Update350
Update350Test.php in modules/lightning_media_video/tests/src/Kernel/Update350Test.php

File

modules/lightning_media_video/src/Update/Update350.php, line 18

Namespace

Drupal\lightning_media_video\Update
View source
final class Update350 implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The media type entity storage handler.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  private $mediaTypeStorage;

  /**
   * The field config entity storage handler.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  private $fieldStorage;

  /**
   * Update350 constructor.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $media_type_storage
   *   The media type entity storage handler.
   * @param \Drupal\Core\Entity\EntityStorageInterface $field_storage
   *   The field config entity storage handler.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation
   *   (optional) The string translation service.
   */
  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);
    }
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * Makes field_media_in_library non-translatable in the video media type.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The I/O handler.
   *
   * @update
   */
  public function removeVideoLibraryFieldTranslatability(StyleInterface $io) {

    /** @var \Drupal\field\Entity\FieldConfig $field */
    $field = $this->fieldStorage
      ->load('media.video.field_media_in_library');
    if ($field) {
      $this
        ->processField($io, $field);
    }
  }

  /**
   * Makes field_media_in_library non-translatable in the video_file media type.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The I/O handler.
   *
   * @update
   */
  public function removeVideoFileLibraryFieldTranslatability(StyleInterface $io) {

    /** @var \Drupal\field\Entity\FieldConfig $field */
    $field = $this->fieldStorage
      ->load('media.video_file.field_media_in_library');
    if ($field) {
      $this
        ->processField($io, $field);
    }
  }

  /**
   * Removes translatability from a field after confirming the action.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The I/O handler.
   * @param \Drupal\field\Entity\FieldConfig $field
   *   The field from which to remove translatability.
   */
  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));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
Update350::$fieldStorage private property The field config entity storage handler.
Update350::$mediaTypeStorage private property The media type entity storage handler.
Update350::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Update350::processField private function Removes translatability from a field after confirming the action.
Update350::removeVideoFileLibraryFieldTranslatability public function Makes field_media_in_library non-translatable in the video_file media type.
Update350::removeVideoLibraryFieldTranslatability public function Makes field_media_in_library non-translatable in the video media type.
Update350::__construct public function Update350 constructor.