-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block Directory: Use plugin API for installing & deleting block-plugins #23219
Conversation
}, | ||
method: 'POST', | ||
} ); | ||
yield addInstalledBlockType( block ); | ||
yield addInstalledBlockType( { ...block, plugin: response.plugin } ); |
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.
This is a bit of a workaround, since we need the main plugin file for uninstallation (ex, blissful-buttons/blissful-buttons.php
, or wp-p5js-block/plugin.php
). I'm not sure if we can/should try adding this to the block directory response (from wp.org), or leave this as-is.
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.
I don't think the block directory response could return that info nor should it.
I'm fine with this approach for now, but since plugin
is a pretty generic property we could run into collisions in the future.
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.
This looks great to me!
One alternative might be to add the self
link to the addInstalledBlockType
instead. That way you don't have to manually construct the route, and can just operate off the link.
@@ -94,18 +95,19 @@ export function* installBlockType( block ) { | |||
* @param {Object} block The blockType object. | |||
*/ | |||
export function* uninstallBlockType( block ) { | |||
const { id } = block; | |||
const plugin = block.plugin.replace( '.php', '' ); |
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.
This is somewhat unexpected, is the plugin file the only way to get the slug?
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.
Right now the plugins controller returns the file. This could be bypassed by using the self
link.
I don't know if the controller should return the file ie my-plugin/init.php
or my-plugin/init
for the plugin field. The former is the "real" value, but the latter is what will get used in the URL. I'm very much open to thoughts.
Ran this locally. Works fine. |
Could this be rebased? Not sure if the test failures are legitimate. |
6c9ac20
to
fa992a7
Compare
Ok, I rebased it. |
Size Change: +640 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
The install and uninstall routes no longer exist on this controller, as they've moved to the plugin controller.
Looks like there's some e2e test failures. |
…ns (#23219) * Block Directory: Use plugin API for installing & deleting block-plugins * Remove the install & uninstall endpoints from the block-directory * Set the endpoint for the block by using the self link property * Remove erroneous route tests The install and uninstall routes no longer exist on this controller, as they've moved to the plugin controller. * Update e2e install mock url to fix tests. Co-authored-by: tellyworth <[email protected]> Co-authored-by: dufresnesteven <[email protected]>
Description
The
/plugins
endpoints were introduced in #22454, and while/block-directory/install
and/block-directory/uninstall
were updated to use those endpoints in PHP, we can actually remove those endpoints and call theplugins
methods directly. See #22454 (comment)This PR updates the install flow to call
POST __experimental/plugins
, and the uninstall flow to callPUT __experimental/plugins/${ plugin }
(to deactivate) andDELETE __experimental/plugins/${ plugin }
to remove the files.It also removes the install & uninstall endpoints from
__experimental/block-directory
, and updates all the tests.How has this been tested?
The php & js unit tests have been updated. I've also tested the block directory flow in browser (chrome):
Checklist: