Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Problem: Widget needs refactoring because:
- Widgets have no interface and base class
- Widgets have no schema definition.
- Widgets cannot be defined with sane config defaultds
- The widget info is not structured inside the facet entity.
Proposed resolution
Fix all the above points.
Remaining tasks
None.
User interface changes
None.
API changes
- Rename
WidgetInterface
to\Drupal\facets\Widget\WidgetPluginInterface
and make it extend\Drupal\Core\Config\Entity\ConfigEntityListBuilder
- Add
::buildConfigurationForm()
toWidgetPluginInterface
. Pass the current facet as argument instead of the facet as config object. - Add a base class:
abstract class WidgetPluginBase extends PluginBase implements WidgetPluginInterface {...}
- Provide default implementations for methods.
- Refactor
\Drupal\facets\Form\FacetForm::buildWidgetConfigForm()
to accept new changes. - Refactor
\Drupal\facets\FacetInterface
and\Drupal\facets\Entity\Facet
to use a more compact version for widget data. - Implement schema for widgets.
Data model changes
Widget info is stored now in facet as:
uuid: ...
id: ...
...
widget: links
widget_configs:
show_numbers: true
soft_limit: 10
...
Make this more compact:
uuid: ...
id: ...
...
widget:
id: links
config:
show_numbers: true
soft_limit: 10
...
Comment | File | Size | Author |
---|---|---|---|
#47 | refactor_widget_plugins-2725453-47.patch | 50.25 KB | borisson_ |
Comments
Comment #2
claudiu.cristeaComment #3
borisson_Comment #4
claudiu.cristeaRefactored a lot. Probably the intediff doesn't help too much. I'm expecting a lot of test failures so, yes, this is just a workin' draft, a start.
I'm not sure that is Novice.
Comment #5
claudiu.cristeaThe patch, sorry.
Comment #8
claudiu.cristeaThis patch needs some love. I'm afraid I don't have time to work on it next period.
I updated the IS to reflect the changes.
BTW: I think the whole facet config structure should be revised before BETA. It's a little bit messy.
Comment #9
claudiu.cristeaComment #10
claudiu.cristeaLast test fixing tentative. Please continue to fix them.
Comment #13
claudiu.cristeaSo, test failures were significantly decreased in #10. Can somebody take over?
Comment #14
borisson_This should fix all unit tests, the integration test is fixed in a way that I'm unhappy with, Hoping to figure out how to fix that better later today.
Comment #15
claudiu.cristeaWow, nice!
Few notes.
Let's add a comment to each to explain the widgets they are referring to.
No. The parent always contains 'show_numbers'. That is common to all widgets.
probably we want to make __construct() pass only $configuration as signature. But that as optional so we can write something like:
Probably
\Drupal\facets\Widget\WidgetPluginBase::__construct
can look as:The we can call the constructor without parameters. Or only with configuration as 1st parameter.
Comment #16
claudiu.cristeaComment #17
borisson_#15
Comment #20
claudiu.cristeaNo sorry, Now there are a lot of unrelated changes now in #17. We need to go back to #14 and apply #15, #16.
On 2. you're not right dropdown is extending the base clsss only so he won't get soft_limit
Comment #21
borisson_@claudiu.cristea I reverted the changes in #17 and also reverted the fix I applied for the integration test in #14.
About #17.2, this is the definition of the dropdown widget of current HEAD:
class DropdownWidget extends LinksWidget {}
, it's the same in the current patch.I reapplied the changes in #17.1 and fixed #17.3.
I expect at least one fail, in the
WidgetIntegrationTest
.Comment #24
marthinal CreditAttribution: marthinal commentedWorking a little bit on it :)
Comment #27
marthinal CreditAttribution: marthinal commentedLet's try again
Comment #28
claudiu.cristea@marthinal, thank you.
Sorry @borisson_, you're absolutely right. I was wrong about class hierarchy. But I feel that the correct inheritance should be:
WidgetPluginBase
- LinksWidget
-- CheckboxWidget
- DropdownWidget
Please correct me if I'm wrong.
What I did.
I didn't run any tests, so failures are possible.
Comment #31
borisson_No worries, That is the correct inheritance, that looks like it makes more sense.
That looks great, I agree with these changes.
Do you think you have time to look at the remaining test failures or do you want me to have a go at them?
Comment #32
borisson_Patch doesn't apply anymore either.
Comment #33
borisson_Patch applies again now. Test still fail though, looking at those now.
Comment #36
borisson_This should fix at least some of the failures.
Comment #39
borisson_This should fix the remaining fail in the Integrationtest, I'll have a look at the last unit test fail after lunch.
Comment #42
borisson_Attached patch should be green.
This now needs another thorough review before we can commit this.
Comment #43
ekes CreditAttribution: ekes as a volunteer commentedReroll
(Three way merge required for Entity and manual merge for Dropdown Widget - there was translation added to the defaults, I've added this back, not sure if that's correct yet).
Comment #46
Nick_vhadd widget_config to the FacetInterface here.
"with the following structure"
isn't it called "configuration" instead of config. And I think you mentioned it is optional?
This will break if the getWidget() function doesn't return an object. We should verify if that value exists before referring to the type. Unless we're 100% sure the getWidget cannot fail? :)
Also rename to $facet, we're using $facet everywhere else don't we?
Same concern here. Don't we need to check the getWidget object actually exists first and fail appropriately?
Is the configuration that is allowed documented somewhere?
same concern here.
Can we add some comments to explain what this is doing?
Other than that, this change looks great. Awesome that we no longer have to extend a linkswidget to create a dropdownwidget ;-)
Comment #47
borisson_Fixed broken tests,
regarding #46:
.1, we store everything in the widget now, the config as well, so we don't have to remove that.
.2 Fixed
.3 It's called config in the .schema.yml, configuration is not optional, it's always available but can change per widget.
.4 a facet without a widget is broken anyway, let's not code for that case because everything will stop working anyway. I did the rename to $facet.
.5 see .4
.6, .7 See .3, all configuration can be allowed, as long as it's provided with a schema.
.8 Sure, added a comment.
If the bots and @Nick_vh approve, we can commit this today.
Comment #48
borisson_Go testbot, go!
Comment #49
Nick_vhGo commit, Go!
Comment #50
Nick_vhComment #52
borisson_Committed.
Comment #53
mpp CreditAttribution: mpp commentedtestFacets() still seems to have a reference to "widget_configs":
Had some trouble with this patch after re-exporting. See https://www.drupal.org/node/2755447.
Comment #54
mpp CreditAttribution: mpp commentedPlease ignore my last comment, I still had some old files locally.