Skip to content

Instantly share code, notes, and snippets.

@virtualLast
Forked from magevision/CustomContent.php
Created March 7, 2022 12:19
Show Gist options
  • Save virtualLast/6697609254c1625e0e7402a352692930 to your computer and use it in GitHub Desktop.
Save virtualLast/6697609254c1625e0e7402a352692930 to your computer and use it in GitHub Desktop.
Add Custom Field To CMS Page
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="content">
<field name="custom_content">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string"/>
<item name="formElement" xsi:type="string">wysiwyg</item>
<item name="source" xsi:type="string">page</item>
<item name="wysiwyg" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">custom_content</item>
<item name="additionalClasses" xsi:type="string">admin__field-wide</item>
</item>
</argument>
</field>
</fieldset>
</form>
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="MageVision\Blog15\Block\CustomContent" name="cms.page.custom.content" after="cms_page" />
</referenceContainer>
</body>
</page>
<?php
namespace MageVision\Blog15\Block;
class CustomContent extends \Magento\Cms\Block\Page
{
/**
* Prepare HTML content
*
* @return string
*/
protected function _toHtml()
{
$html = $this->_filterProvider->getPageFilter()->filter($this->getPage()->getCustomContent());
return $html;
}
}
<?php
namespace MageVision\Blog15\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class InstallSchema implements InstallSchemaInterface
{
/**
* Add Secondary Custom Content
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
$setup->getConnection()->addColumn(
$setup->getTable('cms_page'),
'custom_content',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => '2M',
'nullable' => true,
'comment' => 'Page Custom Content'
]
);
$installer->endSetup();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment