Problem/Motivation

InstanceInterface cannot list the nodes of a slot. A caller digs into the source data, knowing where each source plugin keeps its slots. display_builder_ai counts a slot's children through ['source']['component']['slots'], which only works for components.

Proposed resolution

Add getSlotNodeIds(string $parent_id, string $slot_id): ?array to SourceTree, and delegate to it from InstanceInterface: the node IDs of a slot in order, empty for an empty or unknown slot, NULL when the parent node does not exist.

The other queries first proposed here had no caller, see #3627027-5: InstanceInterface: list the nodes of a slot. Kernel tests on SourceTree and on the instance.

API changes

One new method on InstanceInterface, one on SourceTree. Nothing existing changes.

Command icon 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

mogtofu33 created an issue. See original summary.

mogtofu33’s picture

Assigned: Unassigned » pdureau
Status: Active » Needs review
pdureau’s picture

Assigned: pdureau » mogtofu33

Seven new methods on InstanceInterface, and two on SourceTree. Nothing existing changes. Instance is the only implementation of the interface.

I was expecting the opposite about " Harden InstanceInterface": less public methods, smaller public interfaces, safer commitment for us.

Also, I understood SourceTree as an internal black box to consolidate tricky and risky logic directly used by Display Builder, not as public interface to extends. If we don't use the 2 new methods, why others project would needs them?

So, I am not putting this ticket in RTBC. However, if you own this strategy of extending interfaces and deeply believe in it, go for it.

mogtofu33’s picture

Assigned: mogtofu33 » pdureau

[deleted] wrong comment

mogtofu33’s picture

Assigned: pdureau » mogtofu33
mogtofu33’s picture

I was expecting the opposite about " Harden InstanceInterface": less public methods, smaller public interfaces, safer commitment for us.

I think you misread the Plan, it is not to make smaller but more open to contrib. Makes thinner could be a side effect but not the intended purpose. Example with display_builder_ai that revealed a case we didn't had, and it started a broader plan to ease contrib. Note the plan is not rigid, it's a direction.

For the next part, fair question, and it cuts this issue down to one method.

The plan shrinks too: items 3, 6 and 9 of #3624396: Plan: Harden InstanceInterface, IslandInterface and DisplayBuildableInterface as public API before RC1 deprecate, remove, and mark @internal everything that is not a contract, SourceTree included. But here I derived the methods from what SourceTree can answer, not from callers. Your test is the better one: a public method needs a caller.

Checked against display_builder_ai, the one contrib module changing instances:

  • getSlotNodeIds(): it counts a slot's children through ['source']['component']['slots'], wrong for any parent that is not a component. Kept.
  • getRootNodeIds(): it walks getSources(), which is fine once its node shape is documented. Dropped.
  • hasNode(): getNode() returning NULL covers it. Dropped.
  • isNodeInRoot(), isNodeInSlot(), isRootFull(), isSlotFull(): no caller anywhere. Dropped.
mogtofu33’s picture

Assigned: mogtofu33 » pdureau
mogtofu33’s picture

Title: InstanceInterface: add the tree queries » InstanceInterface: list the nodes of a slot
Issue summary: View changes
pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs review » Reviewed & tested by the community

Checked against display_builder_ai, the one contrib module changing instances:

A single addition to InstanceInterface (::getSlotNodeIds()) to address an identified need in contrib 👍

  • mogtofu33 committed 214e1ad7 on 1.0.x
    task: #3627027 InstanceInterface: list the nodes of a slot
    
    By:...
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.