You are here

function lightning_media_update_8017 in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 lightning_media.install \lightning_media_update_8017()
  2. 8 lightning_media.install \lightning_media_update_8017()
  3. 8.2 lightning_media.install \lightning_media_update_8017()

Changes all image_immutable field widgets to image_image.

File

./lightning_media.install, line 311
Contains install and update routines for Lightning Media.

Code

function lightning_media_update_8017() {
  \Drupal::service('plugin.manager.field.widget')
    ->clearCachedDefinitions();

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
  foreach (EntityFormDisplay::loadMultiple() as $form_display) {
    foreach ($form_display
      ->getComponents() as $key => $component) {
      if ($component['type'] == 'image_immutable') {
        $component['third_party_settings']['lightning_media'] = [
          'file_links' => FALSE,
          'remove_button' => FALSE,
        ];
        $component['type'] = 'image_image';
        $form_display
          ->setComponent($key, $component);
      }
    }
    $form_display
      ->save();
  }
}