Magento 2: How to Create Cms Block Programmatically Using DataPatch
Introduction In the [How to Create Cms Page Programmatically Using DataPatch] chapter I explained why we should use DataPatch in the Magento 2. To create CMS-Block we laso will use DataPatch. It will save our time in the future. Solution <?php namespace Vendor\ModuleName\Setup\Patch\Data; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; use Magento\Cms\Model\BlockFactory; class CreateCmsBlock implements DataPatchInterface, PatchRevertableInterface { /** * @var BlockFactory */ protected BlockFactory $blockFactory; /** * @param BlockFactory $blockFactory */ public function __construct( BlockFactory $blockFactory ) { $this->blockFactory = $blockFactory; } /** * {@inheritdoc} */ public function apply() { $blockData = [ 'title' => 'Test CMS Block', 'identifier' => 'test_cms_block_identifier', 'content' => 'Yau!...