Activating of this module breaks media library

Created on 11 May 2023, about 1 year ago
Updated 12 May 2023, about 1 year ago

Hello everyone, I encountered with next issue :

Fatal error: Class Drupal\media_contextual_crop_field_formatter\Plugin\MediaContextualCropUseCase\References contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Drupal\media_contextual_crop\MediaContextualCropUseCaseInterface::processImage, Drupal\media_contextual_crop\MediaContextualCropUseCaseInterface::processImageUrl) in /project/web/modules/contrib/media_contextual_crop_field_formatter/src/Plugin/MediaContextualCropUseCase/References.php on line 19

Steps to reproduce

install & enable the module and try to check the media library in admin UI - /admin/content/media-grid

Will be grateful for any solutions, thanks!

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @KateKarpenko
  • Status changed to Active about 1 year ago
  • πŸ‡«πŸ‡·France DrDam

    Hooo sorry,

    I have forgot to release the rework of abstract class the 1.1.1 version of MediaContextualCrop

    Can you update media_contextual_crop to 1.1.1 ?
    composer require 'drupal/media_contextual_crop:^1.1'

    Sorry

  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Thank you DrDam for your quick reply!
    And yep - updating to 1.1.1v got it worked.
    Now my media library is not breaking, but I have another issue and am unsure which topic it should be.

    In Content-Type I'm using the field as "Reference/media with contextual modifications" and when I try to use any picture while creating a page I see an error message

    Error message
    Warning: Undefined variable $original_delta in Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget->formElement() (line 425 of core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php).
    Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget->formElement(Object, 0, Array, Array, Object) (Line: 171)
    Drupal\media_library_media_modify\Plugin\Field\FieldWidget\MediaLibraryWithOverrideWidget->formElement(Object, 0, Array, Array, Object) (Line: 353)
    Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 92)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object, NULL) (Line: 286)
    Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget->form(Object, Array, Object) (Line: 183)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
    Drupal\node\NodeForm->form(Array, Object) (Line: 106)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 534)
    Drupal\Core\Form\FormBuilder->retrieveForm('node_test_ct_edit_form', Object) (Line: 281)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
    Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 707)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    

    I use multi_crop_field_formatter with media_contextual_crop_iwc_adapter because I need image_widget_crop.

    I did all settings of Crop type & Image styling using this crop type and everything did according to the docs β†’

    On the edit page form, I can see as it was announced in the doc - the possibility to adjust alt-text and crop for contextual use. After saving the page in the dev tool panel, I inspected the image element. ALT text is applied only for specific node without affecting the original image in the media library as it was expected, but cropping is not applied at all. unfortunately

  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡«πŸ‡·France DrDam

    When you say " After saving the page in the dev tool panel, I inspected the image element", I assume you can see a "overwritten_property_map" attribute ?

    Can you detail configurations :
    - on the content type the "media with contextual" settings/form/view mode
    - on the media image form/view mode on the image field

    Can you check if all patchs are correctly applied ?

    My first impression (following the line number of the error) are that a patch on media_library_media_modify are not correctly installed :
    "Issue #3263397-10: Simplify form logic in media library" => "https://www.drupal.org/files/issues/2023-01-19/3263397-16.patch"

  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Well, applying a patch on media_library_media_modify

      "Issue #3263397-10: Simplify form logic in media library" =>  "https://www.drupal.org/files/issues/2023-01-19/3263397-16.patch"
    

    resolved that error! Thank you!!!

    About the cropping issue - here are my steps:

    1. Created Crop type 16:3
    2. Created Image Style Crop 16:3
    3. Created CT with field as Reference/media with contextual modifications - entity reference to media type Image
    4. On "manage form display for CT" I see for the field "media library extra" widget with next settings:

     Multi edit form on create: true
    No edit form on create: false
    Check selected: true
    Replace checkbox by order indicator: true
    Form mode: default

    5. On manage display tab for CT - I set format for the field "rendered entity" rendered as "Test mode"
    6. Then on Media Type Image - on " manage form display" I set for image ImageWidget crop with next settings

    ImageWidget crop
    Always expand crop area: Yes
    Show default crop area: Yes
    Warn the user if the crop is used more than once: Yes
    Preview image style: large
    Preview crop zone image style: Crop thumbnail
    Crop Type used: crop_16_3

    7. On "manage display" tab I went to the viewmode "Test mode" and set Image as Image format with

    Image style: Crop style 16:3
    Image loading: lazy

    8. Created Test page and put an image from media library with contextual ALT text and crop.
    9. Saved it and went to dev tools and saw that image style should be applied correctly, but on the page image is rendering on original size

    <img src="/sites/default/files/styles/crop_style_16_3/public/2023-05/tokyo-office.jpg?itok=82jO_v-c" width="4721" height="5115" alt="initial alt text 111111" loading="lazy" typeof="foaf:Image">

  • πŸ‡«πŸ‡·France DrDam

    If the patch attached to media_library_media_modify is not auto-applied by composer on your project, I imagine that this one are not too :
    https://www.drupal.org/files/issues/2022-06-08/manage_crops_3270150-7.patch β†’

    This one permit saving crop data in the contextual.

    If it's that, you need to check your composer install...

  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Good point! Thanks!

    I re-installed again all Contextual Crop Ecosystem and all patches are applied correctly except for one

    https://www.drupal.org/files/issues/2022-10-10/patch_media_lib.patch (Add multi_crop_embed filter as managing media_embed)
     Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-10-10/patch_media_lib.patch
    

    but as I see it's for embedded media... not exactly my case...

    And I still have an issue with "crop image style" not rendering on the front

  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Well, I reinstalled Image Widget Crop β†’ and Crop β†’ modules, and for now image cropping styles are working with media field (as entity reference to media).

    But when I try to change the crop for the image (which is the field "media with contextual") - it still uses crop from the original image cropping while rendering on a page, and when I go to the edit form page I can assure that contextual crop is saved.

    What do I need to do for having this contextual cropping on the front as well?

  • Assigned to DrDam
  • Status changed to Needs review about 1 year ago
  • πŸ‡«πŸ‡·France DrDam

    My Bad, the tag 1.1.1 has been placed on the wrong branch...
    Please make a composer update to get the 1.1.2 .

    After getting the right version, please flush caches ...

    Sorry for that.

  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Thank you, I upgraded to the new version already and cleared the cache.

    I've got a new error

    Fatal error: Class Drupal\media_contextual_crop_embed\Plugin\MediaContextualCropUseCase\Embed contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Drupal\media_contextual_crop\MediaContextualCropUseCaseInterface::getContextualUri) in /project/web/modules/contrib/media_contextual_crop_embed/src/Plugin/MediaContextualCropUseCase/Embed.php on line 17

    and I still see that patch cannot be applied

      - Applying patches for drupal/core
        https://www.drupal.org/files/issues/2022-10-10/patch_media_lib.patch (Add multi_crop_embed filter as managing media_embed)
       Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-10-10/patch_media_lib.patch

    Could you fix it, please?

  • πŸ‡«πŸ‡·France DrDam

    well, I'm so sorry, I got confused with the different modules and releases ...
    so please update media_contextual_crop_embed to 1.2.1 release ...

    If you use Ckeditor 5, you can ignore the patch error.

  • πŸ‡ΊπŸ‡¦Ukraine KateKarpenko Kyiv

    Awesome, thanks a lot, I've got it working!
    That's definitely what I need.

    Big thanks to DrDam for the quick response and support.

  • πŸ‡«πŸ‡·France DrDam

    Thanks to you for using this solution

  • Status changed to Fixed about 1 year ago
Production build 0.69.0 2024