Overview
When adding components using the page builder agent, the response sent to the frontend is in the following format format
{
"status": true,
"operations": [
{
"operation": "ADD",
"components": [
{
"id": "sdc.starshot_demo.starshot-columns",
"nodePath": [
1,
0
],
"fieldValues": {
"cols": "two",
"gap": "medium",
"alignment": "none"
}
},
{
"id": "sdc.starshot_demo.starshot-button",
"nodePath": [
1,
0,
0,
0
],
"fieldValues": {
"text": "Read more",
"url": "https:\/\/example.com\/read-more-1",
"display": "primary"
}
},
{
"id": "sdc.starshot_demo.starshot-button",
"nodePath": [
1,
0,
1,
0
],
"fieldValues": {
"text": "Read more",
"url": "https:\/\/example.com\/read-more-2",
"display": "primary"
}
}
]
}
],
}The nodePath value was calculated for each component to be added, and then passed to addNewComponentToLayout to place it in the required position (e.g in a specific region, above or below another component, or inside a specific slot).
But now, after #3538576: Provide a way to programmatically add component with custom values + update values of an existing component got merged, it is no longer possible to pass the nodePath value to the function and therefore the component placement is broken
Proposed resolution
Just noticed that addNewComponentToLayout still supports adding a 'to' param in the payload. So, only this change has to be reverted
User interface changes
Issue fork experience_builder-3543519
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
akhil babuThe nodePath value is critical to place each component at its intended position. For example, if only the content region is enabled and there are no components placed on a page, to add a component like sdc.example.two-column with two sdc.example.heading components in each slot, we could previously calculate the nodePath like this:
Then, components could be added one by one using addNewComponentToLayout.
Similerly, if multiple regions are enabled, componets can be placed at the correct region by giving the proper nodePath.
Eg: if header, content and footer regions are available, then [0, 0] will add a component to the header, [1, 0] to the content and [2,0] to the footer
It would be great if we could bring back the ability to give nodePath directly in the method itself.
Comment #3
akhil babuComment #4
akhil babuComment #5
akhil babuComment #6
akhil babuJust noticed that addNewComponentToLayout still supports adding a 'to' param in the payload. So, only this change has to be reverted
Comment #7
akhil babuComment #9
akhil babuMinor change, Ready for review.
To test this, try any prompt that requires placing components in a specific region or slot, such as
Using page builder, Add a two column layout with 2 'Hello world' heading components in each columns.
Using page builder, Add a two column layout with 2 'Hello world' heading components in each columns, to the header region
Without this change, both headigs would get placed below the two column.
Comment #12
jessebaker commented