You are here

final class Update240 in Lightning Media 8.3

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

Contains optional updates targeting Lightning Media 2.4.0.

Plugin annotation

@Update("2.4.0");

Hierarchy

Expanded class hierarchy of Update240

File

src/Update/Update240.php, line 15

Namespace

Drupal\lightning_media\Update
View source
final class Update240 implements ContainerInjectionInterface {

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

  /**
   * The module installer.
   *
   * @var \Drupal\Core\Extension\ModuleInstallerInterface
   */
  protected $moduleInstaller;

  /**
   * Update240 constructor.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $field_config_storage
   *   The field config storage.
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
   *   The module installer service.
   */
  public function __construct(EntityStorageInterface $field_config_storage, ModuleInstallerInterface $module_installer) {
    $this->fieldConfigStorage = $field_config_storage;
    $this->moduleInstaller = $module_installer;
  }

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

  /**
   * Renames the "Save to my media library" field of all media types.
   *
   * @update
   *
   * @ask Do you want to rename the "Save to my media library" field of all
   * media types to "Show in media library"?
   */
  public function renameSaveToMyMediaLibrary() {

    /** @var \Drupal\field\Entity\FieldConfig[] $field_configs */
    $field_configs = $this->fieldConfigStorage
      ->loadByProperties([
      'field_name' => 'field_media_in_library',
      'entity_type' => 'media',
    ]);
    foreach ($field_configs as $field_config) {
      $field_config
        ->setLabel('Show in media library')
        ->setSettings([
        'on_label' => 'Shown in media library',
        'off_label' => 'Hidden in media library',
      ])
        ->save();
    }
  }

  /**
   * Enables Audio file media.
   *
   * @update
   *
   * @ask Do you want to install "Audio file" media?
   */
  public function enableAudioFileMedia() {
    $this->moduleInstaller
      ->install([
      'lightning_media_audio',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Update240::$fieldConfigStorage private property The field config storage.
Update240::$moduleInstaller protected property The module installer.
Update240::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Update240::enableAudioFileMedia public function Enables Audio file media.
Update240::renameSaveToMyMediaLibrary public function Renames the "Save to my media library" field of all media types.
Update240::__construct public function Update240 constructor.