Created
August 21, 2019 14:59
-
-
Save cgartner-redstage/77fef307ce492d49725300ef0d96218d to your computer and use it in GitHub Desktop.
Example block creating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Magento\Cms\Model\Block; | |
use Magento\Cms\Model\BlockRepository; | |
use Magento\Cms\Model\BlockFactory; | |
// contruct | |
public function __construct( | |
BlockRepository $blockRepository, | |
BlockFactory $blockFactory | |
) | |
{ | |
$this->blockRepository = $blockRepository; | |
$this->blockFactory = $blockFactory; | |
} | |
// code | |
$block = $this->blockFactory->create(); | |
$block->setIdentifier('indentifier'); | |
$html = <<<HTML | |
// html code | |
HTML; | |
$block->setTitle('Block name'); | |
$block->setContent($html); | |
$block->setIsActive(true); | |
$block->setStoreId([0]); // 0 is for all stores | |
$this->blockRepository->save($block); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment