Media Library Add entity-type form_mode config from widget

Created on 22 November 2022, about 2 years ago
Updated 14 August 2024, 4 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 21 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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024