Problem/Motivation
Following the introduction of SourceWithSlotsInterface in #3531521: Layout plugins support, and related to #3574548: Unexpected properties in ComponentSource data.
When we move a slot source to a slot of an implementation of SourceWithSlotsInterface being, or having as ancestor, a non-ComponentSource implementation of SourceWithSlotsInterface, the uppest (at least) SourceWithSlotsInterface implementation lose some data structure.
Yes, it is a very specific situation :)
For example:
- Start a new Page Layout display. It will have the new
PageLayouSourceat the root. This source implementsSourceWithSlotsInterface. - Attach a first
ComponentSourceto the root - Attach a second
ComponentSourceto a slot ofPageLayouSource - Move the second
ComponentSourceto a slot of the firstComponentSource - Result: The first
ComponentSourcelose some data, including thesource_id
Proposed resolution
We may have an undetected leftover of hardcoded ComponentSource logic in Instance entity.
For example, in Instance::moveToSlot() has a magic number ("3") which looks suspicious:
$parent_slot = \array_slice($path, \count($path) - 3, 1)[0
We need to fix that, but also:
- Since beta1 we are introducing more and more coupling to
SourceInterfaceinInstanceentity. Is it the opportunity to embrace this coupling and to rely less on array primitives inInstanceInterface? - Can we add a playwright test using
PageLayoutSourceas the root of the builder? in order to detect those kind of situations in the pipeline?
Issue fork display_builder-3574921
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 commentedWe may need to merge #3573805: Empty renderables in regions prevent layouts rendering before completing this work
Comment #4
pdureau commentedComment #6
pdureau commented#3573805: Empty renderables in regions prevent layouts rendering is merged.
I can resume my work. Not ready for merge yet: it seems the bug is fixed, we are also now totally SDC agnostic; and we have a bunch of kernel tests to check this, but it is at the cost of this mechanism:
This may have unfortunate side effects. Let's see if the playwright tests are OK
Comment #7
pdureau commentedHello Jean,
Here are the challenges of the work done here, once we moved from hardcoded SDC logic to
SourceWithSlotInterface.InstanceSlotOperationsTest and array list indexation
If we have this structure:
If we
Instance::moveToSlot()the source "A" into a slot of "B" we have this unexpected structure:Where the
sourceproperty with the new value is dissociated from thenode_id, thesource_idand the originalsource.Let's take a
Instance::moveToSlot()action, it is divided in 2 internal steps:Instance::doRemove()is reindexing the "B" (from "1" to "0") after the removal of "A":Instance::doAttachToSlot()is still believing "B" is indexed at "1" and merging the array structure teh wrong waySo, in the MR, we moved the reindexing of list indexes (
\array_values($slot));) from::doRemove()to the beginning of::buildIndexFromSlot()and now we have a food source structure but badly indexed ("1" instead of "0"):So, in
InstanceSlotOperationsTest::testMoveFromComponentToNestedLayoutEmptyRegion) test, we considered this OK because we want to keep consistent indexes during the chain of atomic operation and we expect the values to be correctly indexed at the very end, thanks to::buildIndexFromSlot().I hope it was the right bet.
Some change in InstanceHistoryTest
For your information.
Comment #8
mogtofu33 commented