Problem/Motivation
Step by step, DisplayBuildableInterface is becoming big and messy:
public static function getPrefix(): string;
public static function getContextRequirement(): string;
public static function checkInstanceId(string $instance_id): ?array;
public function getBuilderUrl(): Url;
public static function getUrlFromInstanceId(string $instance_id): Url;
public static function getDisplayUrlFromInstanceId(string $instance_id): Url;
public function getProfile(): ?ProfileInterface;
public function getInstanceId(): ?string;
public function initInstanceIfMissing(): void;
public function getInitialSources(): array;
public function getInitialContext(): array;
public function getSources(): array;
public function saveSources(): void;
And not discoverable, so we have added display_builder_provider_info hook.
Proposed resolution
Create a display_builder/Provider plugin type
With attribute discovery. Not configurable.
ProviderInterface:
getProfile(): ProfileInterface(the one saved in config/content, not the one from Instance)getInstance(): InstanceInterfacegetInitialSources(): array;getContextRequirement(): string;getContext(): array;(renamed from getInitialContext())getSources(): array;saveSources(): void;getUrl(): Url(as a replacement of bothgetBuilderUrl()andgetDisplayUrlFromInstanceId)getDisplayUrl(): Url(as a replacement ofgetDisplayUrlFromInstanceId)
We may not need this anymore:
- all static functions taking
instance_idas parameter:checkInstanceId,getUrlFromInstanceId,getDisplayUrlFromInstanceIdbecause we now work on instantiated plugins getPrefix(): not currently used outside the classes. Can be replaced by a plugin attribute.getInstanceId():replaced by getInstance()->id() or something like thatgetInitialSources(): only used inInstanceStorage::createFromImplementation()initInstanceIfMissing(): because implementation always the same, can be moved to a base class
Move DisplayBuildableInterface implementation logic to 4 plugins
- modules/display_builder_entity_view/src/Plugin/display_builder/Provider/EntityView.php
- modules/display_builder_entity_view/src/Plugin/display_builder/Provider/ContentOverride.php
- modules/display_builder_page_layout/src/Plugin/display_builder/Provider/PageLayout.php
- modules/display_builder_views/src/Plugin/display_builder/Provider/ViewDisplay.php
Replace display_builder_provider_info by the plugin type manager
that's it
Issue fork display_builder-3549266
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedLet's play a bit with this subject.
Comment #4
pdureau commentedComment #5
pdureau commentedWorks have started: https://git.drupalcode.org/project/display_builder/-/merge_requests/148
With:
DisplayBuildableInterfaceimplementation from modules/display_builder_page_layout/src/Entity/PageLayout.php to this pluginTests are still green
Next steps:
DisplayBuildableInterfaceas much as possibledisplay_builder_provider_infoby the plugin type manager::getInstance()methodsComment #6
pdureau commentedWork in progress: https://git.drupalcode.org/project/display_builder/-/merge_requests/148
Phase 1: Add new API
Done:
display_builder_provider_infoby the plugin type managerNext steps:
Phase 2: Enjoying the new API
Now we have the new plugin type, we can do some simplification and cleaning:
DisplayBuildableInterfaceas much as possible::getInstance()methodsThis may be done in a follow-up issue.
Comment #7
pdureau commentedToo big and too late for beta1.
Comment #8
pdureau commented#3545474: Security: Set Instance access handler is adding a new method to DisplayBuildableInterface.
Comment #9
pdureau commentedBefore wrapping up (fixing phpunit, tidying up, documentation...), I would be glad to have your input:
(this is not a review before merge, just chit-chatting)
Comment #10
mogtofu33 commentedSome tricky rebase, could you have a look?
Comment #11
pdureau commentedSure
Comment #12
pdureau commentedComment #13
mogtofu33 commentedThere is still conflict on rebase with current 1.0.x.
Comment #14
pdureau commentedComment #15
pdureau commentedThere will always have conflicts because the MR is altering a lot of files and everytime we are committing to 1.0.x a conflict may occurs.
I am rebasing twice a week to keep track of the 1.0.x changes.
There are 3 phpunit errors:
Because of #3562991: Instances list from config and not storage and the challenges of the upcoming #3555110: Symmetric translation, I am now convinced this change is relevant.
Before wrapping up (fixing phpunit, tidying up, documentation...) and planning the follow-up (simplify DisplayBuildableInterface, move some logic to DisplayBuildablePluginBase...), I would be glad to have some input:
(this is not a review before merge, just chit-chatting)
Comment #16
pdureau commentedRebased.
Oops, I may have forgot to remove
display_builder.api.phpfile.Playwright seems OK.
There are still 2 little fails in a single phpunit test
Drupal\Tests\display_builder\Kernel\ConfigFormBuilderTest::testConfigFormBuilderBuild:Unfortunately,
/admin/structure/display-builder/instancesis now broken. It may be related to a change made recently: https://git.drupalcode.org/project/display_builder/-/commit/f413a9a392e8...So it may be the opportunity to replace
DisplayBuilderUiHelpers::getInstancesFromProviders()(and related private methods, so the fullDisplayBuilderUiHelpersfile may be removable) by a cleanerDisplayBuildableInterface::getInstances()static method.Comment #17
christian.wiedemann commentedComment #18
pdureau commentedComment #19
pdureau commentedLet's do rebase and rename the plugin, and try to fix the last phpunit fails.
Christian will review and once in RTBC, Jean will merge when he will be back.
Comment #20
pdureau commentedRebased. So, what have been done?
1. DisplayBuildableInterface as a new plugin type
Added:
modules/display_builder_entity_view/src/Entity/EntityViewDisplayTrait.phptoEntityViewpluginmodules/display_builder_entity_view/src/Field/DisplayBuilderItemList.php(removed) toEntityViewOverridepluginmodules/display_builder_page_layout/src/Entity/PageLayout.phptoPageLayoutpluginmodules/display_builder_views/src/Plugin/views/display_extender/DisplayExtender.phptoViewDisplayplugintests/src/Kernel/DisplayBuildableMock.php(removed) toDisplayBuildableMockplugin2. Add DisplayBuildableInterface::collectInstances()
To fully replace
DisplayBuilderUiHelpers:Implemented in all plugins:
Updated logic:
/admin/structure/display-builder/instancesis still working OK.3. Replace ConfigFormBuilder by DisplayBuildableInterface
ConfigFormBuilder service is heavily dependent of DisplayBuildableInterface, and now we are implementing DisplayBuildableInterface as plugins the service is always loaded alongside DisplayBuildablePluginManager.
We can heavily reduce complexity and (in a follow-up issue) reduce DisplayBuildableInterface surface, by moving ConfigFormBuilder to DisplayBuildablePluginBase.
It will also allow plugins to override some form related methods.
Remaining work
Playwright i still OK.
There are still 2 little fails in a single phpunit test
Drupal\Tests\display_builder\Kernel\ConfigFormBuilderTest::testConfigFormBuilderBuild:Unfortunately, I don't know how to fix them and I would be happy to have assistance here.
Also: Update documentation and graphical schemas
By the way, those plugins must be discovered as:
\Plugin\display_builder\Buildable\\Plugin\display_builder\Integration\InstanceListBuilder)? Namespace discovery:\Plugin\display_builder\Provider\Follow-up
The new architecture opens many opportunities to simplify the codebase. This MR is mostly
DispalyBuildableInterfaceimplementations to a new plugin type, keeping the same logic and the same methods. Very naively, without altering too much.We will create a follow-up ticket with:
DisplayBuildableInterfaceas much as possible::getInstance()methods::getBuilderUrl()⮕::getUrl(),::getDisplayUrlFromInstanceId()⮕::getDisplayUrl(),::getInitialContext()⮕::getContext(),::saveSources()⮕::publish()...Comment #23
pdureau commentedpipeline is green :)
Comment #24
pdureau commentedDocumentation updated.
The MR is adding 92 lines of PHP code but architecture is simpler and clearer:
I am very excited about what we can do as simplifications in a follow-up ticket.
Also, this change is necessary for #3555110: Symmetric translation
Comment #25
mogtofu33 commentedDone some code cleanup and logic, some renaming to avoid confusion and added getPrefix() as attribute value.