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

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

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

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

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

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

        if (isset($pageData['page_layout']) && !empty($pageData['page_layout'])) {
            $data['page_layout'] = $pageData['page_layout'];
        } else {
            $data['page_layout'] = '1column';
        }

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

        $page = $this->pageFactory->create();
        $page = $page->load($data['identifier'], 'identifier');

        if ($page->getId()) {
            $data['page_id'] = $page->getId();
        }

        $page->addData($data);
        $this->pageRepository->save($page);

        if (isset($pageData['config_option'])) {
            $this->saveConfigValue($pageData['config_option'], $data['identifier'], 0);
        }
    }
private function createCmsPage($pageData)
    {
        // Check if template filename exists
        $filename = $pageData['filename'];
        $template = $this->getTemplatePath('pages') . $filename;
        // phpcs:ignore
        if (!file_exists($template)) {
            return;
        }

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

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

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

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

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

        if (isset($pageData['page_layout']) && !empty($pageData['page_layout'])) {
            $data['page_layout'] = $pageData['page_layout'];
        } else {
            $data['page_layout'] = '1column';
        }

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

        $page = $this->pageFactory->create();
        $page = $page->load($data['identifier'], 'identifier');

        if ($page->getId()) {
            $data['page_id'] = $page->getId();
        }

        $page->addData($data);
        $this->pageRepository->save($page);

        if (isset($pageData['config_option'])) {
            $this->saveConfigValue($pageData['config_option'], $data['identifier'], 0);
        }
    }
private function createCmsPage ( $ pageData ) { // Check if template filename exists $ filename = $ pageData [ 'filename' ] ; $ template = $ this -> getTemplatePath ( 'pages' ) . $ filename ; // phpcs:ignore if ( ! file_exists ( $ template ) ) { return ; } // Remove filename from data unset ( $ pageData [ 'filename' ] ) ; // Fetch template content // phpcs:ignore $ templateContent = @ file_get_contents ( $ template ) ; $ data = [ 'stores' => [ 0 ] , 'is_active' => 1 , ] ; if ( preg_match ( '/<!--@title\s*(.*?)\s*@-->/u' , $ templateContent , $ matches ) ) { $ data [ 'title' ] = $ matches [ 1 ] ; $ data [ 'content_heading' ] = $ matches [ 1 ] ; $ templateContent = str_replace ( $ matches [ 0 ] , '' , $ templateContent ) ; } if ( preg_match ( '/<!--@identifier\s*((?:.)*?)\s*@-->/us' , $ templateContent , $ matches ) ) { $ data [ 'identifier' ] = $ matches [ 1 ] ; $ templateContent = str_replace ( $ matches [ 0 ] , '' , $ templateContent ) ; } if ( isset ( $ pageData [ 'page_layout' ] ) && ! empty ( $ pageData [ 'page_layout' ] ) ) { $ data [ 'page_layout' ] = $ pageData [ 'page_layout' ] ; } else { $ data [ 'page_layout' ] = '1column' ; } /**
         * Remove comment lines
         */ $ content = preg_replace ( '#\{\*.*\*\}#suU' , '' , $ templateContent ) ; $ content = trim ( $ content ) ; $ data [ 'content' ] = $ content ; $ page = $ this -> pageFactory -> create ( ) ; $ page = $ page -> load ( $ data [ 'identifier' ] , 'identifier' ) ; if ( $ page -> getId ( ) ) { $ data [ 'page_id' ] = $ page -> getId ( ) ; } $ page -> addData ( $ data ) ; $ this -> pageRepository -> save ( $ page ) ; if ( isset ( $ pageData [ 'config_option' ] ) ) { $ this -> saveConfigValue ( $ pageData [ 'config_option' ] , $ data [ 'identifier' ] , 0 ) ; } }
Create a cms page with the given data

@param array $pageData
Create a cms page with the given data