Media Library Add entity-type form_mode config from widget

Created on 22 November 2022, over 1 year ago
Updated 23 January 2024, 5 months ago

Problem/Motivation

A project we're working on needs two different form modes for the media-instance Add forms on e.g. a Node field. The difference is per field, and so configuration would be in the field widget.

In this case the need arises because some media fields need to use manual crop for the image while others need a focal point method, and so a single form mode (media_library) is insufficient to the task.

Steps to reproduce

The media library hard-codes both the form mode and the preview image style using the name 'media_library', the form mode being set in AddFormBase.php. There are no workarounds.

Proposed resolution

A patch is presented which introduces a new select element on the media library widget, together with the needed changes to the MediaLibraryState object to pass this value along to the place it's needed in AddFormBase::buildForm().

Remaining tasks

I think this works. Test code has been adjusted so it still works, but no new test code has been added.

This patch includes some changes to source formatting mostly to reduce line lengths to somewhat reasonable limits.

User interface changes

A new Select element is added to the Media Library Form widget. It defaults to the existing value (Media Library | media_library).

API changes

A new class, "media_library_form_mode--" + the form mode, is added to the <form> element.

Data model changes

The MediaLibraryState has been extended, but initializations have compatible defaults.

It is possible that media embed code might need adjusting as well (as has been done here for ckeditor).

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom rivimey

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡±Poland Graber

    Styling of links got broken after some recent core update. Going for a local solution and documenting here in case this issue got more attention again eventually:
    in implementation of hook_preprocess_links__media_library_menu()

    $variables['#attached']['library'][] = 'core/drupal.vertical-tabs';
    
  • πŸ‡΅πŸ‡±Poland Graber

    Ok, actually it's a core issue and has nothing to do with the work here. Reproduced on a clean instance with no patch.
    Ignore my last comment please.

Production build 0.69.0 2024