Problem/Motivation
Inspired from both:
- The current work to make instance entity translatable & revisionable (#3579299: Tidy context management, #3578469: Make instance entities aware of display buildables, #3562989: Implements RevisionLogInterface for Instance entity & finally
#3555110: Symmetric translation) - #3581893: Fix and cleanup which is introducing
ON_RESTORE&ON_RESETevents and movingEntityViewOverridemechanisms out ofApiController::revert()
We are observing the emergence of 2 distinct behaviours related to Instance & Events:
State alterations
Those methods and events never reach the DisplayBuildable plugins and alter only the Instance entity and its "volatile" storage (through SourceTree): attachToRoot, attachToSlot, moveToSlot, remove...

Publishing
Those methods and events pass through the DisplayBuildable plugins and alter the Instance entity and the permanent storage: publish (actually save in some part of the code, let's tidy that), restore & revert

Proposed resolution
It is important to distinct those 2 mechanisms to secure the upcoming code changes, so we know we have 2 clear paths, one where DisplayBuildable must never be called, and one where they are the leading logic.
On controllers
Introduce ApiPublishingController
| From | To |
| ApiController::save() | ApiPublishingController::publish() (and rename the related display_builder.api_save route to display_builder.api_publish, with its path)
|
| ApiController::restore() | ApiPublishingController::restore()
|
| ApiController::revert() | ApiPublishingController::revert() |
And split related tests.
On Instance entity
Introduce PublishableInterface
In Instance entity methods:
| From | To |
InstanceInterface::canSaveContextsRequirement()
| PublishableInterface::isPublishable() (we can also remove the parameter)
|
InstanceInterface::hasSaveContextsRequirement()
| (whatever, it will not last anyway) |
InstanceInterface::saveIsCurrent()
| PublishableInterface::isPresentPublished() or ::isPublishedPresent()
|
InstanceInterface::setSave()
| (whatever, it will not last anyway) |
InstanceInterface::hasSave()
| PublishableInterface::isPublished() |
There is also EntityPublishedInterface, but it doesn't seem to match our model.requirements?
So, the newly introduced PublishableInterface looks like something like that:
interface PublishableInterface {
public function restore(): void;
public function isPublished(): ?int;
public function isPresentPublished(): bool;
public function isPublishable(): bool;
}Surprisingly, publish() and revert() are not needed yet in this new interface, but it will happen soon
And we can extract InstancePublishingTest from InstanceHistoryTest & InstanceTest
On events
- Rename
ON_SAVEevent toON_PUBLISH - Rename
onSave()subscriber method toonPublish() - More?
Other
There are some strings and comments here and there referencing "save" instead of "publish".
| Comment | File | Size | Author |
|---|
Issue fork display_builder-3582234
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 commentedComment #3
pdureau commentedComment #5
mogtofu33 commentedComment #6
mogtofu33 commentedComment #7
pdureau commentedHello @mogtofu33,
What do you think about the MR https://git.drupalcode.org/project/display_builder/-/merge_requests/263/... ?
The 2 main changes, which are important to make next developments easier are:
PublishableInterfacewith better named methodsI also did some splits following
PublishableInterfacescope, less immediately useful but which make sense to me:Are you OK? Would it be relevant to also split
IslandEventSubscriberInterfaceand the events classes? Do we need more documentation about this distinction?Comment #8
mogtofu33 commentedThanks for that.
You right we could split events as well, and
ON_REVERTshould probably be moved indisplay_builder_entity_viewmodule.In the meantime I would like to move interface used by a single or very few classes to related folder, will propose a commit. So we keep only cross based interfaces in src.
And create a src/Island layer for Island related classes. Will add a commit for that too.
Comment #9
pdureau commentedCould restore stay something generic but only used by entity view display for now?
Maybe upcoming display buildable plugins from contrib or custom projects will need such mechanism.
Comment #10
mogtofu33 commentedRight, I revert a change and move back to split event and subscribers with interfaces.
Comment #11
mogtofu33 commentedLooking good, let merge, keep open for feedback.
Comment #13
pdureau commentedThe goal of this issue was to make the distinction between:
attachToRoot,attachToSlot,moveToSlot,remove...publish,restore&revertSomething clear, simple and welcoming for contributors.
However, we landed with:
ON_HISTORY_CHANGE,ON_RESTORE,ON_REVERTON_ATTACH_TO_ROOT,ON_MOVE,ON_UPDATEON_ATTACH_TO_SLOTON_DELETEON_ACTIVE,ON_PUBLISHonActiveonHistoryChange,onRestore,onRevertonPublish,onPresetSaveonAttachToRoot,onAttachToSlot,onMove,onUpdate,onDeleteSo, we have some issues here:
METHOD_INTERFACE_MAPinIslandFanOutTrait, the match increateEventWithEnabledIsland, 1200 lines added in total, and a 120 linesarchitecture.mdneeded to have some idea of what is happening hereON_PUBLISHis withON_ACTIVEbutonPublishis withonPresetSave)ON_DELETElost the Node ID, I guess because we are not using it right now in available islands but we need to be future-proof, and keep sending the useful information)So I am proposing to merge back the events and the interfaces:
ApiController/ApiPublishingControllerandInstanceInterface/PublishableInterfacesplits introduced in this MRComment #19
pdureau commentedI am opening a new MR to prepare the first proposal ("merge back the events and the interfaces as single files like it was before") : https://git.drupalcode.org/project/display_builder/-/merge_requests/265
There are still some mention of removed interfaces in docs & comments, but most of the work is done. I hope it will help.
If you believe the second proposal ("... with 2 files each following
ApiController/ApiPublishingControllerandInstanceInterface/PublishableInterfacesplits") is better, go ahead.Comment #21
mogtofu33 commentedMy goal was to prepare something to have events more flexible and isolated to let a custom island create and use it's own events. Like for
ON_PRESET_SAVE, ON_REVERT and ON_HISTORY_CHANGE which are specific to an island feature and not 'core'. Best being a custom module to be able to simply add a feature (api + event + island).
Revert here and will do on other MR for that to do it properly.
I am not sure about your 'future proof' point, we have data in the event but the subscriber force fixed parameters, so we already assume and force the event behavior, ON_DELETE node id passed but not used is an example of this 'de-sync'.
Comment #25
mogtofu33 commented