I am creating module which will create static block & cms page at time of site transfer.
So my InstallData
file like below :
class InstallData implements InstallDataInterface
{
/**
* @var BlockRepositoryInterface
*/
private $blockRepository;
/**
* @var BlockInterfaceFactory
*/
private $blockInterfaceFactory;
private $pageFactory;
public function __construct(
PageFactory $pageFactory,
BlockRepositoryInterface $blockRepository,
BlockInterfaceFactory $blockInterfaceFactory
) {
$this->pageFactory = $pageFactory;
$this->blockRepository = $blockRepository;
$this->blockInterfaceFactory = $blockInterfaceFactory;
}
/**
* Installs data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$this->createCopyRightBlock();
}
public function createCopyRightBlock()
{
$cmsBlock = $this->blockInterfaceFactory->create();
$content = "<div class='copy-right'><p>Copyright © 2017 Test Title</p></div>";
$identifier = "copy-right";
$title = "Copy Right Block";
// We can then use the exposed methods from
// \Magento\Cms\Api\Data\BlockInterface to set data to our CMS block
$cmsBlock->setData('stores', [0])
->setIdentifier($identifier)
->setIsActive(1)
->setTitle($title)
->setContent($content);
// And use the \Magento\Cms\Api\BlockRepositoryInterface::save
// to actually save our CMS block
$this->blockRepository->save($cmsBlock);
} }
I want to check if there is static block with same identifier exists then script execution will be skip.
Please advice me how can i make condition for that.
Thanks