Skip to content
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

Add reference widgets to legacy widget blocks. Use ajax admin endpoint on this blocks. #15801

Open
wants to merge 1 commit into
base: master
from

Conversation

@jorgefilipecosta
Copy link
Member

commented May 23, 2019

Description

Fixes: #16604

This is a WIP it's working correctly but I still need to check the code to improve it.

During the widgets RFC, we decided that existing widgets will be referenced in the legacy widgets and the real instance should be updated in these cases.
This PR uses the ajax admin endpoint to implement this concept of referencing widgets in the legacy widgets block.
This mechanism is also used to implement callback widgets so this PR supersedes #14395 and allows us to avoid the hack $_POST = array_merge( $_POST, $instance_changes ); present in the other PR.
The rest endpoint is used to get the initial form of all widgets (the ajax admin does not seem to allow that), and it is used to provide the update logic in class widgets that don't have an instance. That endpoint should be read-only unless the widgets apply changes in methods that should not have side-effects.
The ajax admin is used to perform updates on legacy widgets that reference a real widget instance present in the database.

How has this been tested?

I pasted the following code in the block editor:

<!-- wp:legacy-widget {"widgetClass":"WP_Widget_Archives","identifier":"archives-12"} /-->

<!-- wp:legacy-widget {"widgetClass":"WP_Widget_Archives","identifier":"archives-11"} /-->

<!-- wp:legacy-widget {"widgetClass":"WP_Widget_Media_Audio","identifier":"media_audio-26"} /-->

(Update identifier to real widget instances that were create using the widgets screen).

I verified the legacy widget block works as expected and if I open the widgets screen the changes I did appear there.

I used "NattyWP feedburner widget". The widget comes with silesia theme that can be downloaded at wordpress.org/themes/silesia. The theme is not updated to WordPress 5.0 and some warning messages appear. For testing purposes, the widget can also be used standalone by pasting the code available themes.trac.wordpress.org/browser/silesia/1.0.6/include/widgets/feedburner.php in the functions.php of any other theme.

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch 3 times, most recently from 24127bd to f63259e May 24, 2019

@jorgefilipecosta jorgefilipecosta changed the title And reference widgets to legacy widget blocks. Use ajax admin endpoint on this blocks. Add reference widgets to legacy widget blocks. Use ajax admin endpoint on this blocks. May 28, 2019

@jorgefilipecosta jorgefilipecosta added this to Legacy widgets issues/tasks in Widgets May 30, 2019

@noisysocks

This comment has been minimized.

Copy link
Member

commented May 31, 2019

This is a WIP it's working correctly but I still need to check the code to improve it.

Is it still a WIP?

@jorgefilipecosta

This comment has been minimized.

Copy link
Member Author

commented Jun 3, 2019

Is it still a WIP?

It suffered a huge rebase but is ready for a review.
With these changes, the legacy widgets should load and allow edits on the widget screen. Preview is not working because it is pending on #15635.

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch from 89c7546 to c936b9f Jun 26, 2019

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch 3 times, most recently from 3932ba8 to 7618e8d Jun 27, 2019

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch from 7618e8d to ceec72c Jul 9, 2019

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch from ceec72c to 1d23913 Aug 20, 2019

@jorgefilipecosta

This comment has been minimized.

Copy link
Member Author

commented Aug 20, 2019

This PR was rebased. In my tests, it worked well after the rebase.
It fixes issue #16604, so we should get it in.
@noisysocks do you have some availability to review the PR?

@noisysocks

This comment has been minimized.

Copy link
Member

commented Aug 30, 2019

Really really cool to see the Legacy Widget block working and doing stuff!

I'm a little confused, how does this fix #16604? When I don't have any plugins installed and insert a Legacy Widget block, I still see an empty dropdown:

Screen Shot 2019-08-30 at 16 30 18


It's really apparent that we need to show the title of the widget in the block. For example, you can't tell at all that this is a Search widget:

Screen Shot 2019-08-30 at 16 31 15

widgets.php solves this by having a header with the title in it:

Screen Shot 2019-08-30 at 16 33 26


I tried testing this PR with Image Widget, which was the first plugin I found when searching the directory for "widget".

I was able to insert a Legacy Widget block and select Image Widget, but then I was not able to interact with the widget at all. Clicking on Select Image just caused the page to reload.

I had similar problem with other third party widget plugins that I tested.

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch 2 times, most recently from 3e00946 to b525de5 Sep 2, 2019

@jorgefilipecosta jorgefilipecosta force-pushed the add/legacy-widget-by-id branch from b525de5 to a4ceeb0 Sep 3, 2019

@jorgefilipecosta

This comment has been minimized.

Copy link
Member Author

commented Sep 3, 2019

Hi @noisysocks,

I'm a little confused, how does this fix #16604? When I don't have any plugins installed and insert a Legacy Widget block, I still see an empty dropdown:

Previously we were showing "Block Areas" widget in legacy widgets. This PR fixes that. The empty dropdown was a bug and not it shows as expected a message saying there is no widget available.

I tried testing this PR with Image Widget, which was the first plugin I found when searching the directory for "widget".

I was able to insert a Legacy Widget block and select Image Widget, but then I was not able to interact with the widget at all. Clicking on Select Image just caused the page to reload.

There are some known problems where some third-party widgets don't work because of relying on a specific dom.
A good way to test legacy widgets is enabling the core widgets by setting the array set on https://github.com/WordPress/gutenberg//blob/a4ceeb0159b6dab27a68c122c9c86c4559258b87/lib/widgets.php#L94 to empty.
Core Widgets should work as expected as they rely on the expected widget events.

That said the Image widget seems to work on my tests:
Sep-03-2019 14-33-14

Is there any error being logged during your tests?

@jorgefilipecosta

This comment has been minimized.

Copy link
Member Author

commented Sep 3, 2019

It's really apparent that we need to show the title of the widget in the block. For example, you can't tell at all that this is a Search widget:

We show the currently selected widget in the inspector:
image

We are trying to follow what's happening in other blocks. If we have multiple paragraph blocks, it is not easy to tell which type of paragraph a block is. The user would only know by selecting the block and checking its name on the inspector.
But on widgets, the problem is bigger as most widgets look the same.
cc: @mapk

@mapk

This comment has been minimized.

Copy link
Contributor

commented Sep 6, 2019

It's really apparent that we need to show the title of the widget in the block.

I'm torn on this one. I'd like to stay inline with how we treat other blocks. But in this case, it's not a block, it's a widget inside a block. Can we adopt the reusable block pattern of displaying a name? Maybe we don't include the "Edit" button in this case though.

Screen Shot 2019-09-06 at 2 20 06 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.