I am creating the homepage fixtures for a Sulu application.
I have created a service page type, and I have created a custom type to use on the homepage called service_slider, which is a slider of cards created from the service pages.
The service_slider type contains a smart_content property called services which admins can use to select the service pages to render as cards in the slider.
This works fine when manually choosing the service pages in the admin section, but I am having real trouble figuring out how to do this programmatically in the fixtures.
The homepage fixtures I have look like this:
$homeDocument->getStructure()->bind([
//...
'blocks' => [
'type' => 'service_slider',
'title_text' => 'Lorem ipsum',
'services' => // ???
]
]);
For clarity, the smart content property xml looks like this (simplified):
<property name="services" type="smart_content">
<params>
<param name="provider" value="pages"/>
</params>
</property>
I have tried passing in PageDocument objects and page uuids, I have looked at the Sulu Rocks demo site and code and tried to copy and modify what they have in there (In the DocumentFixture class they have a fixture that adds Articles to a Blog post which is a smart content field) but everything I do results in the services
array being empty when I dump()
out the contents in twig.
Does anybody have any suggestions?
The structure of the data looks in all cases the same as the PUT
or POST
request when you are saving your page. So when you are unsure how a specific field type / content type need to be defined in the fixtures.
Create a new page, fill the field you are interesting in it and see how your Browser is sending the data to the endpoint. And so you know how to structure the array for the fixtures.
In case of smart content is something like this:
'services' => [
'dataSource' => '<uuid>',
'sortBy' => 'published',
'sortMethod' => 'asc',
],
Check also the Demo Data Fixtures for self reference smart content: