private function createCmsBlock($blockData)
    {
        // Check if template filename exists
        $filename = $blockData['filename'];
        $template = $this->getTemplatePath('blocks') . $filename;
        // phpcs:ignore
        if (!file_exists($template)) {
            return;
        }

        // Remove filename from data
        unset($blockData['filename']);

        // Fetch template content
        // phpcs:ignore
        $templateContent = @file_get_contents($template);

        $data = [
            'stores'    => [0],
            'is_active' => 1,
        ];

        // Find title
        if (preg_match('/<!--@title\s*(.*?)\s*@-->/u', $templateContent, $matches)) {
            $data['title'] = $matches[1];
            $templateContent = str_replace($matches[0], '', $templateContent);
        }

        // Remove comment lines
        $content = preg_replace('#\{\*.*\*\}#suU', '', $templateContent);
        $content = trim($content);
        $data['content'] = $content;

        $block = $this->blockFactory->create();
        $block = $block->load($blockData['identifier'], 'identifier');

        if ($block->getId()) {
            $data['block_id'] = $block->getId();
        }

        $data['identifier'] = $blockData['identifier'];
        $block->addData($data);
        $this->blockRepository->save($block);
    }
private function createCmsBlock($blockData)
    {
        // Check if template filename exists
        $filename = $blockData['filename'];
        $template = $this->getTemplatePath('blocks') . $filename;
        // phpcs:ignore
        if (!file_exists($template)) {
            return;
        }

        // Remove filename from data
        unset($blockData['filename']);

        // Fetch template content
        // phpcs:ignore
        $templateContent = @file_get_contents($template);

        $data = [
            'stores'    => [0],
            'is_active' => 1,
        ];

        // Find title
        if (preg_match('/<!--@title\s*(.*?)\s*@-->/u', $templateContent, $matches)) {
            $data['title'] = $matches[1];
            $templateContent = str_replace($matches[0], '', $templateContent);
        }

        // Remove comment lines
        $content = preg_replace('#\{\*.*\*\}#suU', '', $templateContent);
        $content = trim($content);
        $data['content'] = $content;

        $block = $this->blockFactory->create();
        $block = $block->load($blockData['identifier'], 'identifier');

        if ($block->getId()) {
            $data['block_id'] = $block->getId();
        }

        $data['identifier'] = $blockData['identifier'];
        $block->addData($data);
        $this->blockRepository->save($block);
    }
private function createCmsBlock ( $ blockData ) { // Check if template filename exists $ filename = $ blockData [ 'filename' ] ; $ template = $ this -> getTemplatePath ( 'blocks' ) . $ filename ; // phpcs:ignore if ( ! file_exists ( $ template ) ) { return ; } // Remove filename from data unset ( $ blockData [ 'filename' ] ) ; // Fetch template content // phpcs:ignore $ templateContent = @ file_get_contents ( $ template ) ; $ data = [ 'stores' => [ 0 ] , 'is_active' => 1 , ] ; // Find title if ( preg_match ( '/<!--@title\s*(.*?)\s*@-->/u' , $ templateContent , $ matches ) ) { $ data [ 'title' ] = $ matches [ 1 ] ; $ templateContent = str_replace ( $ matches [ 0 ] , '' , $ templateContent ) ; } // Remove comment lines $ content = preg_replace ( '#\{\*.*\*\}#suU' , '' , $ templateContent ) ; $ content = trim ( $ content ) ; $ data [ 'content' ] = $ content ; $ block = $ this -> blockFactory -> create ( ) ; $ block = $ block -> load ( $ blockData [ 'identifier' ] , 'identifier' ) ; if ( $ block -> getId ( ) ) { $ data [ 'block_id' ] = $ block -> getId ( ) ; } $ data [ 'identifier' ] = $ blockData [ 'identifier' ] ; $ block -> addData ( $ data ) ; $ this -> blockRepository -> save ( $ block ) ; }
Create a cms block with the given data

@param array $blockData
Create a cms block with the given data