-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Media / Attachments REST API endpoint: update attachments controller to support flip and to customize attachment fields. #71861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…erride existing endpoint - Introduced `Gutenberg_Media_Processing_REST_Attachments_Controller` to manage attachment endpoints. - Updated `gutenberg_filter_attachment_post_type_args` to use the new controller. - Added functionality to override the REST controller for the `attachment` post type. - Removed the deprecated `Gutenberg_REST_Attachments_Controller` and its associated tests. This change improves the handling of media processing in the Gutenberg editor.
…ng and consistency - Updated PHP files to ensure consistent indentation and formatting in `Gutenberg_REST_Attachments_Controller`, `rest-api.php`, and associated test files. - Enhanced readability by aligning comments and code structure. - Ensured all files end with a newline for better compatibility. These changes contribute to cleaner code and maintainability in the Gutenberg REST API for attachments.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
- Added exclusion for `mock-image-editor.php` in `phpcs.xml.dist` to prevent linting errors. - Enhanced documentation in `mock-image-editor.php` to clarify its purpose and usage in tests, including a reference to the corresponding class in WordPress Core. These changes improve code quality and maintainability in the testing environment.
…and update filter - Removed the unused `$post_type` parameter from `gutenberg_filter_attachment_post_type_args` function. - Updated the `add_filter` call to reflect the change in the number of accepted arguments. These changes enhance code clarity and maintainability in the Gutenberg media processing functionality.
| * Class Gutenberg_Media_Processing_REST_Attachments_Controller. | ||
| */ | ||
| class Gutenberg_REST_Attachments_Controller extends WP_REST_Attachments_Controller { | ||
| class Gutenberg_Media_Processing_REST_Attachments_Controller extends Gutenberg_REST_Attachments_Controller { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extending non-experimental attachment class to avoid naming conflicts.
| <?php | ||
|
|
||
| /** | ||
| * Mock image editor for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to mock the image editor class.
| return $args; | ||
| } | ||
|
|
||
| add_filter( 'register_post_type_args', 'gutenberg_filter_attachment_post_type_args', 10, 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The register_attachment_post_type_args filter is more specific and runs after the general register_post_type_args filter.
This ensures the integrity of the inheritance chain:
WP_REST_Attachments_Controller
↓
Gutenberg_REST_Attachments_Controller (WordPress 6.9 compatibility)
↓
Gutenberg_Media_Processing_REST_Attachments_Controller (Media experiment)
cc @swissspidy or @adamsilverstein for a confidence check and whether you needed register_post_type_args specifically. I smoke tested the media processing experiment and couldn't find any issues.
| $this->assertSame( | ||
| array(), | ||
| gutenberg_filter_attachment_post_type_args( array(), 'post' ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer required due to switch to register_attachment_post_type_args
| case 'flip': | ||
| /* | ||
| * Flips the current image. | ||
| * The vertical flip is the first argument (flip along horizontal axis), the horizontal flip is the second argument (flip along vertical axis). | ||
| * See: WP_Image_Editor::flip() | ||
| */ | ||
| $result = $image_editor->flip( 0 !== (int) $args['flip']['vertical'], 0 !== (int) $args['flip']['horizontal'] ); | ||
| if ( is_wp_error( $result ) ) { | ||
| return new WP_Error( | ||
| 'rest_image_flip_failed', | ||
| __( 'Unable to flip this image.', 'gutenberg' ), | ||
| array( 'status' => 500 ) | ||
| ); | ||
| } | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flips image.
| $original_attachment_post = get_post( $attachment_id ); | ||
|
|
||
| // Check request fields and assign default values. | ||
| $new_attachment_post = $this->prepare_item_for_database( $request ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets and sanitizes any incoming caption, description, and title, post and alt_text fields
lib/compat/wordpress-6.9/class-gutenberg-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
|
Flaky tests detected in 2904c80. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17967475714
|
…ntroller - Updated the `Gutenberg_REST_Attachments_Controller` to handle both vertical and horizontal flipping of images by modifying the request structure. - Refactored the test case to reflect the new functionality, adding a separate test for vertical flipping.
|
Since this doesn't affect any functionality in Gutenberg, I don't see why the PR is made against this repo. I strongly suggest making a PR for WP core directly. |
Yet. It's here for the case where follow up experiments, that rely on these changes, are added to the plugin. There are a couple of things we'd like to try so best to be flexible. Edit: if it's looking like we run out of time to do any of these things before 6.9 beta then I can revert if eventually gets in. |
On reflection, looking at the back-of-the-napkin list (try flip controls in the block editor, experimental new media library package just for example), I think I've changed my mind. I'll get the backport up tomorrow and close this PR given the 6.9 timeline. Any development can be done on the back of the WordPress trunk branch I suppose. Thanks for the nudge. |
|
Closing in favor of WordPress/wordpress-develop#10041 |
What?
This PR is the first step to enhance media editor capabilities as described in #55238 Phase 3: Collaboration > Media Library.
It adds the following functionality:
caption,description, andtitle,postandalt_textfields.Resolves #71863
Core trac ticket: https://core.trac.wordpress.org/ticket/64035
Why?
As outlined in #55238, the extended functionality will allow folks to start experimenting with a redesigned media library.
It will also allow flip controls in the existing image block toolbar.
How?
Gutenberg_Media_Processing_REST_Attachments_Controller.Testing Instructions
For the new tests:
npm run test:unit:php:base -- --filter Gutenberg_REST_Attachments_Controller_TestEnsure that all tests pass (after updates to media processing tests)
npm run test:unit:phpManual testing
Check that existing use of the
media/{$id}/editendpoint has no regressions:media/{$id}/edittook place with the correct payload./wp-admin/upload.phpMedia processing experiment smoke testing
If you have time, smoke test the media processing experiment since this PR changes a few of the hooks and class names:
(Taken from #70623)