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