Commit a359c84a authored by Andrey Vitushkin's avatar Andrey Vitushkin
Browse files

Issue #3291789 by Nelo_Drup, apaderno, EPAM Systems: Notice: Undefined index:...

Issue #3291789 by Nelo_Drup, apaderno, EPAM Systems: Notice: Undefined index: weight in Drupal\image_field_to_media\Form\ImageFieldToMediaForm->setWeightForDisplays()
parent 58ec1d0d
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -332,12 +332,16 @@ class ImageFieldToMediaForm extends FormBase {
    foreach (array_keys($view_modes) as $view_mode) {
      $storage = $this->entityTypeManager->getStorage('entity_view_display');
      $view_display = $storage->load($entity_type . '.' . $bundle . '.' . $view_mode);

      $image_component = $view_display->getComponent($image_field_name);

      // A view display like a "Teaser" may not have the image field. In this
      // case the "$image_component" will be NULL. So, we should check it out.
      if ($image_component) {
        $media_component = $view_display->getComponent($media_field_name);
        $media_component['weight'] = $image_component['weight'];
        $view_display->setComponent($media_field_name, $media_component)->save();
      }
    }

    // ---------- Set for Form displays ------------------------.
    $form_modes = $this->entityDisplayRepository->getFormModeOptionsByBundle($entity_type, $bundle);