Problem/Motivation
The Files administration page use a query object to select the files to display on the page. This query is executed from the form builder. Like any query, this one can be altered using hook_query_alter(). But since there is no tag or metadata attached to the query, it is hard to only alter this specific query. Also, while hook_form_FORM_ID_alter can be used to add element to this form (file_entity_admin_files), it cannot be easily used to add fields to filter the displayed files. there is no way to pass information from the form to the query alter hook implementation.
Proposed resolution
Adding a tag would ease usage of hook_query_alter() (or hook_query_TAG_alter) to alter the query used to select the displayed files. Adding the $form_state to the query metadata, would allow easy usage of submitted values when altering the query.
API changes
This proposed solution does not change the existing API. It provide a new hook to safely alter the administration page: hook_query_admin_files_alter (actually hook_query_TAG_alter).
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | add_tag_and_metadata_to_admin_files_query-1298838-4.patch | 922 bytes | pbuyle |
| #1 | add_tag_and_metadata_to_admin_files_query-1298838-1.patch | 963 bytes | pbuyle |
Comments
Comment #1
pbuyle commentedComment #2
pbuyle commentedAs sample use case, with the patch in #1, the following code can be used to add some basic filter to the page:
Comment #3
dave reidFile entity has switched to a 7.x-2.x branch and the 7.x-1.x branch is no longer used. Please make sure to update your Git clones.
Comment #4
pbuyle commentedHere is the updated patch.
Comment #5
acbramley commented+1 for this feature, I needed a filename filter on this page and this patch allowed that easily (thanks for the example too btw :)
Comment #6
ParisLiakos commented#4: add_tag_and_metadata_to_admin_files_query-1298838-4.patch queued for re-testing.
Comment #7
ParisLiakos commentedyeah, very good for DX :)
thanks commited
Comment #8.0
(not verified) commentedApply issue template.