Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Panel’s image picking flow by replacing the static <select>-driven picker with an AJAX-loaded thumbnail picker that refreshes each time the images modal opens. It also introduces a new XHR backend endpoint to provide file metadata as JSON and extends the Modal component with before-open/before-close hooks.
Changes:
- Refactor
ImagePickerto fetch and render image thumbnails dynamically via a newpanel.files.listXHR endpoint. - Add
onBeforeOpen/onBeforeClosehooks toModaland useonBeforeOpento refresh the image list whenever the images modal opens. - Add backend route + controller action to return file lists as JSON for the picker.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| panel/views/fields/page/imagepicker.php | Replaces <select> with a hidden input and provides the XHR URL for dynamic loading. |
| panel/src/ts/components/modal.ts | Adds before-open/before-close callbacks and dispatches them during open/close. |
| panel/src/ts/components/inputs/image-picker.ts | Implements AJAX-driven thumbnail rendering and selection handling. |
| panel/src/ts/components/inputs/editor/markdown/commands.ts | Refreshes the image picker each time the images modal opens. |
| panel/src/ts/components/form.ts | Updates Form’s ImagePicker binding from HTMLSelectElement to HTMLInputElement. |
| panel/config/routes/routes.php | Registers the new panel.files.list XHR route. |
| formwork/src/Panel/Controllers/FilesController.php | Adds FilesController@list JSON endpoint to serve file metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a significant refactor and enhancement to the image picker functionality in the panel, shifting from a static
<select>-based approach to a dynamic, AJAX-powered image selection UI. It also adds a new backend endpoint to serve file lists as JSON, and improves modal event handling for better UI responsiveness.Key changes include:
Image Picker Refactor & Enhancements
ImagePickercomponent to use a hidden<input>instead of a<select>, and now dynamically loads available images via an AJAX request to a new backend endpoint, displaying image thumbnails for selection. This provides a more user-friendly and interactive image selection experience. [1] [2] [3] [4]insertImagecommand in the markdown editor to trigger an update of the image picker UI every time the images modal is opened, ensuring the latest images are always displayed.ImagePickerin the relevant commands file for better type safety.Backend API & Routing
FilesController@listaction that returns a JSON list of files (with metadata such as filename, URI, size, type, thumbnail, etc.), with proper permission and error handling.panel.files.listto expose the above action as a POST XHR endpoint for use by the frontend.Modal Event Handling Improvements
onBeforeOpenandonBeforeClosehooks to theModalclass, and ensured these callbacks are dispatched at the appropriate times, allowing components to react before a modal is shown or hidden (e.g., to refresh content). [1] [2] [3]