Error when trying to add a field after updating from multi_crop module

Created on 22 January 2024, 10 months ago
Updated 24 January 2024, 10 months ago

Problem/Motivation

I have a project that was a Drupal 9.5 project which was using the multi_crop module.
For being able to update the project to Drupal 10, I followed the Migration Process steps to shift the project from using multi_crop to using media_contextual_crop, media_contextual_crop_field_formatter, media_contextual_crop_fp_adapter, media_contextual_crop_iwc_adapter. Everything including the drush multi_crop:migrateToMediaContextualCrop command was successful. After that I was able to update the project to Drupal 10.

But now when I try to add a field to a Block type, I get the error:

TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in in_array() (line 43 of modules/contrib/media_contextual_crop_iwc_adapter/media_contextual_crop_iwc_adapter.module).
media_contextual_crop_iwc_adapter_form_alter(Array, Object, 'field_ui_field_storage_add_form') (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'field_ui_field_storage_add_form') (Line: 841)
Drupal\Core\Form\FormBuilder->prepareForm('field_ui_field_storage_add_form', Array, Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
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: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
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: 28)
Drupal\Core\StackMiddleware\ContentLength->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: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

- have D9.5 project with working multi_crop module
- Follow the Migration steps for the multi_crop module
- Update the website to Drupal 10 (10.2.2)
- Try to edit a Block type or Node type and add a field

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium flyke

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

Comments & Activities

  • Issue created by @flyke
    • a48b6095 committed on 2.0.x
      Issue #3416292: Error when trying to add a field after updating from...
    • a59a82b3 committed on 2.0.x
      Issue #3416292: Error when trying to add a field after updating from...
  • πŸ‡«πŸ‡·France DrDam

    It's strange, I push an updated control for this on dev version.

    Happy New Year to you and thank you for continuing to trust me by using this solution

  • Assigned to DrDam
  • πŸ‡§πŸ‡ͺBelgium flyke

    Hi, thanks for the fast update, the error is gone now !
    I like the concept of what these modules provide: a way to crop a Media Library image. And the fact that you can have different crops on different places from the same media image, so thank you for that.
    I do feel that the current implementation is cumbersome, many setup steps, and many modules needed to get it all working.
    The main problem I have at this moment is that you cannot get it working so you can choose between different crops (like square, hero,, 16:9). You can have the Form Display setup so that you can do this. But in the end you need to set the Mange Display to a single Cropped image style in which you can only apply a single crop style.

    Just ranting, but ideal scenario, which is probably impossible:
    - You need to install only 1 single module
    - The module has a settings page where you select which image styles should be available for cropping. It only shows existing image styles with a defined width and height
    - It should just work with existing Media reference fields, so no need to create new 'Media with contextual modifications' field type
    - In the Form Display of the Media reference field you should have a new widget: 'Media Library + Cropping'
    - That should allow users to select item from media library and then select which crop type they would like to apply to the image (see settings from step 2: available crop types come from the selected image styles that should be available for cropping. No need to manually create crop types)
    - In the Manage Display for the Media reference field you should have a new widget: 'Cropped image'
    - That widget should retrieve which crop is applied, and then render the cropped image. So no need to manually create crop image styles or select a single cropped image style in Manage Display for the Media reference field.

    I now that this does not take into account cropping from withing ckeditor5, its just what my ideal 'add cropping capability to existing project' workflow would look like.

    In summary: the dream scenario to add cropping to an existing project
    - Install 1 module
    - Select which image styles should be available for cropping
    - Change Widget in Form Display of existing Media reference field
    - Change widget in Manage display of existing Media reference field
    - Done

    And the current steps which I find a bit too cumbersome:
    - Install and enable 4 modules
    - Create Crop types
    - Create new image styles for each crop type
    - Instead of using existing Media reference, you need to add a new 'Media with contextual modifications' field. Which is really a pain in the ass for existing content, because now you have to list all your existing content (both local, on staging, on development, on production, ...), you first need to add the new field and make the existing Media reference field not required, then deploy the new field, then edit all existing content and migrate the Media field to the Media with contectual modifications field, hope you did not miss any existing content, and only after all that migration is done you can remove the old existing Media reference field so you are using only the new field.
    - Edit your Image Media type, add a new Form Display or edit an existing one
    - Select the ImageWidget Crop widget for the Image field, select the available crop types
    - Edit your 'Media with contextual modifications' field Form Display and use the Media Library Extra field and select the Form display from the step above
    - Now you need to edit the Manage Display of your 'Media with contextual modifications' field. You can choose 'Thumbnail' and select 1 cropped image style (so when editing if you chose to apply a different crop style then you have a problem). Or you can choose 'Rendered Entity' in which case you need to select which 'Manage Display' type of your Image Media entity will be rendered, and then you also need to create or edit that Manage Display style of your Image Media entity, and there you can use the 'Contextual Crop Image'widget, which also forces you to select exactly one predifined image style, which is still a problem If you chose a different crop when editing than that selected image style.
    - Done. But cropping will only work if out of the available crop types you only apply the crop type of which you used the corresponding Image Style in the Manage Display settings..

  • πŸ‡«πŸ‡·France DrDam

    I'm totaly aggreed with you : this modules collection is just a particularly badly put together patch only because on the Drupal Core side they still have not understood the impact of adding the media_library on the construction of image styles (and the side effect on "manual crop" feature).
    As for the CROP module and its plugins (focal_point, IWC), the position is one of wait-and-see: "the Core doesn't allow us to do it, so we don't do it".

    I modestly tried to find a solution, a POC to show that:
    1- it’s a real problem
    2- there is a real use
    3- they must decide to move on the Crop & Core side

    The ideal scenario that you describe corresponds to what I would like Drupal Core (stand-alone/out-of-box) to offer

    media_library_media_modify and it's "Media with contextual modifications" are just here because the "evolution" of entity_reference fields ( see this issue ✨ Override media fields from the reference field Postponed ) are blocked for some UI questions (WTF...)

    Thank you for this feedback, and if the original anomaly is corrected, I will mark the ticket as resolved

  • Status changed to Fixed 10 months ago
  • Status changed to Fixed 10 months ago
  • πŸ‡«πŸ‡·France DrDam

    Released in 2.0.2

  • πŸ‡§πŸ‡ͺBelgium flyke

    Thank you @DrDam for explaining how we got here and why we have what we have now. I appeciate it very much.
    So we are waiting (on Drupal core) for a design first on how to do media modifications. Then we need concensus / approval. Then it the necessary development needs to happen, and after that, Media cropping can be a lot leaner and cleaner than what we have now.

Production build 0.71.5 2024