Make WordPress Core

Opened 12 months ago

Closed 11 months ago

Last modified 11 months ago

#64035 closed enhancement (fixed)

Media / Attachments REST API endpoint: update attachments controller to support flip and to customize attachment fields

Reported by: ramonopoly Owned by: ramonopoly
Priority: low Milestone: 6.9
Component: REST API Version: 6.9
Severity: minor Keywords: has-patch has-unit-tests
Cc: Focuses: rest-api

Description

The Media Library editor allows flipping an object and also updating image metadata.

The Media / Attachments REST API /media/{$id}/edit endpoint is currently used to edit images in the block editor, but has limited capability in terms of editing functions.

An incremental approach is preferred here, but a first step to enhance media editor capabilities as described in
Phase 3: Collaboration > Media Library is to add this functionality, namely:

  • the ability to flip an image horizontally and vertically
  • the ability to send arguments to update the new image's caption, description, and title, post and alt_text fields.

Gutenberg PR 71861 is underway, which will be followed by a Core backport patch.

Change History (8)

This ticket was mentioned in PR #10041 on WordPress/wordpress-develop by @ramonopoly.


12 months ago
#1

  • Keywords has-patch has-unit-tests added

## 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:

  • the ability to flip an image horizontally and vertically
  • the ability to send arguments to update the new image's caption, description, and title, post and alt_text fields.

## Why?

As outlined in https://github.com/WordPress/gutenberg/issues/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.

## Testing Instructions

### Unit tests

npm run test:php -- --filter WP_Test_REST_Attachments_Controller

### Manual testing

Check that existing use of the media/{$id}/edit endpoint has no regressions:

  1. Insert an image into a post
  2. Click on the crop symbol in the toolbar of the image block
  3. Edit and save the image.
  4. Check in the Network tab of your browser's console that the POST to media/{$id}/edit took place with the correct payload.
  5. Check that a new file has been created in the Media Library /wp-admin/upload.php

Trac ticket: https://core.trac.wordpress.org/ticket/64035

@andrewserong commented on PR #10041:


12 months ago
#2

I like this change, I think it's going to be really useful to be able to add both flip support and update metadata at the same time in a single API call 👍

For some of the failures, it looks like the b/tests/qunit/fixtures/wp-api-generated.js fixtures need to be updated? I'm not quite sure how to do that, but it looks like it's generated by this PHP function / test:

https://github.com/WordPress/wordpress-develop/blob/5d5235f0001420bebb4ea9e58755c7d526629aa4/tests/phpunit/tests/rest-api/rest-schema-setup.php#L212

@andrewserong commented on PR #10041:


12 months ago
#3

Ah, it looks like you can update the fixtures by running the PHP tests locally, but specifically the following appears to just run the init tests to regenerate those fixtures:

npm run test:php -- --filter "WP_Test_REST_Schema_Initialization"

@ramonopoly commented on PR #10041:


12 months ago
#4

For some of the failures, it looks like the b/tests/qunit/fixtures/wp-api-generated.js fixtures need to be updated?

Thanks! I had to look up a previous comment of mine to remind myself how to do it 😄

https://github.com/WordPress/wordpress-develop/pull/5604#issuecomment-1788236109

@ramonopoly commented on PR #10041:


11 months ago
#5

I'll merge this today. Thanks!

#6 @ramonopoly
11 months ago

  • Owner set to ramonopoly
  • Resolutionfixed
  • Status newclosed

In 60908:

Attachments REST API endpoint: update attachments controller to support flip and to customize attachment fields

This commit enhances media editor capabilities pursuant to the Phase 3: Collaboration > Media Library. See https://make.wordpress.org/core/2023/07/07/media-library/

It adds the following functionality:

  • the ability to flip an image horizontally and vertically
  • the ability to send arguments to update the new image's captiondescription, and titlepost and alt_text fields.

Props ramonopoly, mukesh27, isabel_brison, andrewserong.
Fixes #64035.

@ramonopoly commented on PR #10041:


11 months ago
#7

Committed in r60908

#8 @ramonopoly
11 months ago

  • Milestone Awaiting Review6.9
Note: See TracTickets for help on using tickets.