Motivation
It is currently not possible to select images from the media library when filtering or paging the view.
Proposed resolution
The issue seems slightly related to https://www.drupal.org/project/drupal/issues/2504115, but the fix proposed there does not resolve the issue described here. I've attached a patch that does resolve the immediate problem, be it in a technically not quite correct manner. Any suggestion for a better way to fix this issue is much appreciated!
Steps to reproduce
- Enable the media library
- Add some images to the library
- Add an entity reference field to a node
- Configure the field to use the media library widget
- Add a node, open the media libary widget
- Use the form to sort, filter or page the media items
- Select an image
Expected behaviour
The image selected in the modal form should be the image added to the entity reference field.
Actual behaviour
A different image is selected. For example: if the first image of the second page is selected in the modal, the first image of the first page will actually be used.
The media library does POST the correct media IDs, but MediaLibrarySelectForm discards the posted IDs and used the index of the selection to find the media IDs in the rendered view. Because the page ID (and sort/filter params) do not get posted in the AJAX selection request, only media items of the first page can be selected.