You are here

final class Update400 in Lightning Media 8.4

Same name in this branch
  1. 8.4 src/Update/Update400.php \Drupal\lightning_media\Update\Update400
  2. 8.4 modules/lightning_media_document/src/Update/Update400.php \Drupal\lightning_media_document\Update\Update400

Contains configuration updates targeting Lightning Media Document 4.0.0.

Plugin annotation

@Update("4.0.0");

Hierarchy

Expanded class hierarchy of Update400

1 file declares its use of Update400
Update400Test.php in modules/lightning_media_document/tests/src/Kernel/Update400Test.php

File

modules/lightning_media_document/src/Update/Update400.php, line 16

Namespace

Drupal\lightning_media_document\Update
View source
final class Update400 implements ContainerInjectionInterface {
  use StringTranslationTrait;

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

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

  /**
   * Update400 constructor.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $field_storage
   *   The field config entity storage handler.
   * @param \Drupal\Core\Entity\EntityStorageInterface $media_type_storage
   *   The media type entity storage handler.
   */
  public function __construct(EntityStorageInterface $field_storage, EntityStorageInterface $media_type_storage) {
    $this->fieldStorage = $field_storage;
    $this->mediaTypeStorage = $media_type_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $entity_type_manager = $container
      ->get('entity_type.manager');
    return new static($entity_type_manager
      ->getStorage('field_config'), $entity_type_manager
      ->getStorage('media_type'));
  }

  /**
   * Makes the Document media type's source field required.
   *
   * @param \Symfony\Component\Console\Style\StyleInterface $io
   *   The I/O style.
   *
   * @update
   */
  public function requireDocumentMediaSourceField(StyleInterface $io) {

    /** @var \Drupal\Core\Field\FieldConfigInterface $field */
    $field = $this->fieldStorage
      ->load('media.document.field_document');
    if ($field && $field
      ->isRequired() == FALSE) {
      $question = (string) $this
        ->t('Do you want to make the @field field required on the @media_type media type?', [
        '@field' => $field
          ->getLabel(),
        '@media_type' => $this->mediaTypeStorage
          ->load('document')
          ->label(),
      ]);
      if ($io
        ->confirm($question)) {
        $field
          ->setRequired(TRUE);
        $this->fieldStorage
          ->save($field);
      }
    }
  }

}

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.
Update400::$fieldStorage private property The field config entity storage handler.
Update400::$mediaTypeStorage private property The media type entity storage handler.
Update400::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Update400::requireDocumentMediaSourceField public function Makes the Document media type's source field required.
Update400::__construct public function Update400 constructor.