space48/magento2-cms-content-setup

Provides tooling for initial CMS content creation by FE developer using install scripts and fixtures

0.1.0 2021-04-23 07:09 UTC

This package is auto-updated.

Last update: 2024-05-18 19:20:30 UTC


README

Magento2 module to simplify CMS content creation.

Purpose

This tool is designed to allow frontend developer easily install CMS Pages and Blocks skeletons with 'Lorem ipsum' or actual content at the early stage of the project.

Developer can create a content on local machine, then create a fixtures out of the database data generated by Page Builder or by WYSIWYG. Then add install scripts or data patches to install the data automatically on all CI environments and other developers local machines.

Installation

Via composer:

  • Add module:
composer config repositories.space48-magento2-cms-content-setup vcs git@github.com:Space48/magento2-cms-content-setup.git
composer require "space48/magento2-cms-content-setup:{module-version}"
  • Run setup:upgrade

Usage

  1. Install 'CmsContentSetup' module on your project
  2. Create a separate module for fixtures and install scripts (for ex. MyProject/CmsSetup)
  3. Create a html files containing your CMS Blocks or Pages code under 'fixtures' folder of your module.
  4. Create a Data Patch or install scripts in your module for installing Blocks and Pages.

Example Data Patch for CMS Block:

public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        \Space48\CmsContentSetup\Model\Setup\Blocks $blockSetup
) {
    $this->moduleDataSetup = $moduleDataSetup;
    $this->blockSetup = $blockSetup;
}

...

public function apply()
{
    $this->moduleDataSetup->startSetup();

    $this->blockSetup->install(
        [
            [
                'title' => 'Test Block',
                'identifier' => 'test_block',
                'file' => 'MyProject_CmsSetup::blocks/test/test_block.html', // starting from 'fixtures' folder
                'stores' => ['nl', 'fr'], // can be id or code
                'is_active' => true
            ]
        ]
    );

    $this->moduleDataSetup->endSetup();
}

Example Data Patch for CMS Page:

public function __construct(
    ModuleDataSetupInterface $moduleDataSetup,
    \Space48\CmsContentSetup\Model\Setup\Pages $pagesSetup
) {
    $this->moduleDataSetup = $moduleDataSetup;
    $this->pagesSetup = $pagesSetup;
}

...

public function apply()
{
    $this->moduleDataSetup->startSetup();

    $this->pagesSetup->install(
        [
            [
                'title' => 'Test Page',
                'page_layout' => '1column',
                'meta_keywords' => '',
                'meta_description' => '',
                'identifier' => 'test_page',
                'content_heading' => 'Content Heading',
                'layout_update_xml' => '',
                'url_key' => 'test_page',
                'stores' => ['de', 'fr'], // code or id
                'sort_order' => 0,
                'is_active' => true,
                'file' => 'MyProject_CmsSetup::pages/test_page.html', // starting from 'fixtures' folder
            ]
        ]
    );

    $this->moduleDataSetup->endSetup();
}