The focal point option isn't in the select on Media images field

Created on 17 January 2024, 10 months ago
Updated 19 January 2024, 10 months ago

Hi again :)

I don't know if the problem is with this module or with the Media Contextual Cropping Field Formatter module...

Problem/Motivation

I have a content type with a Media image.
I have installed this adapter to be able to use with Media images.
I don't get the option to choose it in the form display field.
I have used the different dev versions of the module required by Contextual Crop since this is an innovative project ;)
Also I have created a crop type (it was the one created by Focal point module) and an image style.
In images that are not media, it does show in the select.

One thing strange is that after installing it with drush, this module is not listed in the modules pages (I have searched with adapter and also look all the modules with Contextual).

Modules installed:

  • Media Contextual Cropping API
  • Media Contextual Crop Reference
  • Focal Point
  • Media Contextual Cropping with focal_point Plugin
  • Media Contextual Focal Point Adapter

If you need more information, please ask :)

Steps to reproduce

  • Have a content type with a Media image field
  • Install de modules
  • Make a crop type and an image style.
  • Clear registry
  • Go to the content type display form and in the Media image field try to select Focal point.

Merci again and bon nuit :)

💬 Support request
Status

Fixed

Version

2.0

Component

User interface

Created by

🇪🇸Spain candelas

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

Comments & Activities

  • Issue created by @candelas
  • 🇫🇷France DrDam
    Have a content type with a Media image field

    you must use a "Media with contextual modifications" instead of native "entity reference" field.

    In term of configuration :
    1. In the content type, you just need the "media with contextual modifications" field type, and it's configured like a "native entity reference" field type (mainly render mode of the media)
    2. In the MEDIA BUNDLE, you need to set :
    - in the form mode : use the widget focal_point
    - in the view mode (choose in the content_type view_mode) : use the formater "Context crop image" on the field_image, and select a image_style who use the focal crop.

  • 🇪🇸Spain candelas

    Thanks again!
    I am almost there! Only the last step...!
    You say:

    In the view mode (choose in the content_type view_mode) : use the formater "Context crop image" on the field_image, and select a image_style who use the focal crop.

    I get only "Media library extra" :O

    A pleasure to learn from you :)

  • 🇪🇸Spain candelas

    In /admin/structure/types/manage/story/form-display

  • 🇪🇸Spain candelas

    And one question more.
    I used Image field to media to convert a migrated image field to Media field.
    So now I would need another module to make the migration to Media with contextual modifications, wouldn't I?

  • 🇫🇷France DrDam

    You say:

    In the view mode (choose in the content_type view_mode) : use the formater "Context crop image" on the field_image, and select a image_style who use the focal crop.

    I get only "Media library extra" :O

    In the view mode configuration of the media image => admin/structure/media/manage/image/display

    And one question more.
    I used Image field to media to convert a migrated image field to Media field.
    So now I would need another module to make the migration to Media with contextual modifications, wouldn't I?

    In fact, the module "media_library_media_modify" provide a service to migrate a "standard" reference field to a "Media with contextual" field
    Drupal\media_library_media_modify\EntityReferenceOverrideService::migrateEntityReferenceField([entity_type], [field_name]);
    So you can use Image field to media to made the "image->ref media" conversion and the service of media_library_media_modify to made "ref media -> media with contextual" conversion

  • 🇪🇸Spain candelas

    Sorry this morning meetings.
    I got it!
    but now when I save or delete a selected media I get an error.

    Drupal\Core\Entity\EntityStorageException: 'context' not found in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of /var/www/html/donestech10.devel/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    I don't know in which of your modules report this...

    Thanks thanks a lot for your patience, you can be a teacher, you know? ;)

  • 🇪🇸Spain candelas

    mmm how do I know?

  • 🇪🇸Spain candelas

    in media_contextual_crop I don't see a patch...
    do I put it in my composer.json?

  • 🇫🇷France DrDam

    run a composer reinstall drupal/crop

    you may have a

      - Installing drupal/crop (2.3.0): Extracting archive
      - Applying patches for drupal/crop
        https://www.drupal.org/files/issues/2023-11-06/%232617818-31-provide_contextual_capability_to_crops.patch (provide_contextual_capability_to_crops)
    
  • 🇪🇸Spain candelas

    patch applied, cleared the registry and I keep with the error.
    Maybe I have to create the field again?

  • 🇫🇷France DrDam

    can you check the database, if the field exist in "crop_field_data" table ? if it's it may be a bug in your code...

  • 🇪🇸Spain candelas
    The website encountered an unexpected error. Try again later.
    
    Drupal\Core\Entity\EntityStorageException: 'context' not found in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
    
    Drupal\Core\Entity\Query\Sql\Tables->addField() (Line: 58)
    Drupal\Core\Entity\Query\Sql\Condition->compile() (Line: 176)
    Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 81)
    Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 177)
    _media_contextual_crop_field_formatter_get_crops_from_entity_field() (Line: 91)
    media_contextual_crop_field_formatter_entity_update()
    call_user_func_array() (Line: 409)
    Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 388)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 416)
    Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 217)
    Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
    Drupal\Core\Entity\ContentEntityStorageBase->invokeHook() (Line: 564)
    Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 781)
    Drupal\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 489)
    Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
    Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 352)
    Drupal\Core\Entity\EntityBase->save() (Line: 270)
    Drupal\node\NodeForm->save()
    call_user_func_array() (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
    Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
  • 🇪🇸Spain candelas

    Yes, the field crop_field_data exists in the database.

  • 🇪🇸Spain candelas

    the fields:
    cid
    vid
    type
    langcode
    entity_id
    entity_type
    uri
    height
    width
    x
    y
    default_langcode
    revision_translation_affected

  • 🇫🇷France DrDam

    Can you make a

    drush fbi crop

    did you see the "context" field too ?

    Second question : did you have some crop already saved ?

  • 🇫🇷France DrDam

    "crop_field_data" is a table, not a field ... and it seems there is no "context" (data)field in it.

  • 🇪🇸Spain candelas

    drush fbi crop
    ------------------------------- ---------- ------------------ -------------
    Field name Required Field type Cardinality
    ------------------------------- ---------- ------------------ -------------
    cid integer 1
    uuid uuid 1
    vid integer 1
    type entity_reference 1
    langcode language 1
    entity_id integer 1
    entity_type string 1
    uri uri 1
    height integer 1
    width integer 1
    x integer 1
    y integer 1
    context string_long 1
    revision_timestamp created 1
    revision_uid entity_reference 1
    revision_log string_long 1
    default_langcode boolean 1
    revision_default boolean 1
    revision_translation_affected boolean 1
    ------------------------------- ---------- ------------------ -------------

  • 🇪🇸Spain candelas

    I don't have crops saved because the error...

  • 🇪🇸Spain candelas

    I go to delete de field and make it with a different name.

  • 🇪🇸Spain candelas

    The same.
    I have in the Media type image crops saved.
    I go to try to create a different one in case that it is that.

  • 🇫🇷France DrDam

    did you have some message in "/admin/reports/status" page about entity ?

    because, it seems the field are known in the registry, but not present in database ...

  • 🇪🇸Spain candelas

    I have made a new crop and a new field but still have the problem.
    I go to make it in a fresh install.

  • 🇫🇷France DrDam

    the bug are you table crop_field_data doesn't have the "data field" context even the entity registry have it.

    in fact, you don't need to try to create a field or a crop, as long as the Crop module is activated, the patch apply and the table does not contain the field, it won't work.

  • 🇪🇸Spain candelas

    But why does the context data field is not created? how can I solve that?

  • 🇫🇷France DrDam

    It can be the most obvious and stupid reason : did you have made an drush updb after the patch apply ?

  • 🇪🇸Spain candelas

    glups... I am ashamed ....
    I have done drush updb and we have the field and CAN SAVE!!!!
    I am very tired and I forgot... thanks for the patience.

    And the last thing, how do I assign the different styles, I go to the /admin/config/media/responsive-image-style , don't I?

  • 🇫🇷France DrDam

    The main way (node -> media -> image -> style) :

    - In the node "view mode" you choose the "view mode" it will be used for the media
    - In the media "view mode" you choose (for the image field) the formater "contextual image crop" with the image_style you have set to use a crop (focal point / manual crop).

    The responsive image way ( node -> media -> responsive image -> styles) :

    Responsive image is something else, it permit you to configure some "break-point" and determine which "image style" using in each break-point (I didn't explain you how configure a responsive-image-style).
    - In this case, in the media "view mode" you will choose the "Responsive image" formater and the "responsive_image_style" you have set.

  • 🇪🇸Spain candelas

    Thank you. If you come to Barcelona, I will cook a paella for you :)

    I know break-points with the breakpoints module that now is responsive images from D7.
    Now I am confused with the crop entity.
    With the main way (node -> media -> image -> style), how do I assign the image style for each break-point so with the focal point configuration the images for each are created?

  • 🇫🇷France DrDam

    In the "normal way", there isn't have break-point. The image (in the media) are render use a single style.

    If your need are to use break-points (in ordre to rendre the image in mulitple style), you need use Responsive-image module.

  • Status changed to Fixed 10 months ago
  • Status changed to Fixed 10 months ago
Production build 0.71.5 2024