-
Notifications
You must be signed in to change notification settings - Fork 2
CMS Content
Code Slicer edited this page Sep 12, 2022
·
3 revisions
For CMS related stuff, we have both CmsPage
and CmsBlock
facades, for.. well, what their names imply.
To import them:
private Migration\Facade\CmsBlock $cmsBlock;
private Migration\Facade\CmsPage $cmsPage;
public function __construct(
Migration\Context $context,
Migration\Facade\CmsBlock $cmsBlock,
Migration\Facade\CmsPage $cmsPage
) {
$this->cmsBlock = $cmsBlock;
$this->cmsPage = $cmsPage;
}
Their share exactly the same methods, as described below:
Create a new entry on the database for given content. Ex.:
$this->cmsPage->create('my-new-page', [
'title' => 'Lorem Ipsum',
'content' => <<<HTML
<span>Hello World!</span>
HTML,
]);
Update the content of existing cms content.
$this->cmsBlock->update('footer', [
'title' => 'Lorem Ipsum',
'content' => <<<HTML
<ul>// page builder generated stuff</ul>
HTML,
]);
Literally what the name implies, optionally restricting the scope to a single store.
$this->cmsBlock->delete('winter-offers-2022');
Check if a page/block with given identifier already exists on the database. Useful for some situations where you just to create a content if it don't exists yet.
if (!$this->cmsBlock->exists('winter-offers-2023')) {
$this->cmsBlock->create('winter-offers-2023', [...$data]);
}
Converts any given identifier to its respective id. Useful for creating pages with new blocks simultaneously:
We want YOU for our community 🫵