v3Importing composite modules
- Create a page from admin area and add that module to it (if it not exists already)
- Search for that page in database and copy from 'modules' field the JSON string
- Go to http://jsonviewer.stack.hu/ (or any other json viewer) and copy the JSON string for the composite module that you need
- Create a method in Project/Bundle/CmsBundle/Entity/Collection/PageEditorModuleCollection.php ...lets say setGallery
php
public function setGallery(array $images)
{
$moduleStr = '{
"selector": ".article .content_grid_home .sliders-container",
"position": 0,
"moduleId": "admin\/slider\/slider",
"data": {
"moduleList": [
%____moduleListModules_____$s
],
"collection": [
%____collectionModules_____$s
]
},
"settings": [
],
"html": "some html here %_____htmlItems______$s ....",
"id": 3
}
';
$moduleStr = sprintfn($moduleStr, [
'____moduleListModules_____' => trim(implode(',', $moduleListItemsStr),'"'),
'____collectionModules_____' => trim(implode(',', $collectionItemsStr),'"'),
'_____htmlItems______' => trim(implode('', $collectionItemsHTMLStr),'"')
]);
$module = json_decode($moduleStr, true);
$this->add($module);
}
$moduleListItemsStr, $collectionItemsStr, $collectionItemsHTMLStr - array with strings specific to each modules (in our case we had a iteration of images and we should reproduce the same slide for each image) - this modules are deducted from point 2
Based on JSON module from database we should recreate the module with the informations that we have to import. After we rebuilt the module with the new informations we just need to call the method with
php
$page->setGallery($images)