Magento 2 Commerce Cloud – Page Builder
One of the nice features in Magento 2 Commerce Cloud is the Page Builder addition to the admin panel. This is a user-friendly visual WYSIWYG improvement, which gives admin users great control over their content.
That said, there are certain situations when you want a block in the admin panel to just be the “traditional” WYSIWYG editor. Page Builder adds some HTML wrappers to your content, which can prove challenging if the block in question is being used inline, or within a menu.
Global Page Builder Toggle
Magento 2 gives you the ability to enable or disable Page Builder within the admin panel. However, this is a global setting, meaning it affects all CMS pages, blocks and other content areas which use Page Builder.
Disable For Specific Blocks
Cadence Labs has developed a lightweight extension which will disable Page Builder for specific blocks you define within the system configuration.
Install The Extension
Simply install the extension from our github here: https://github.com/cadencelabs/pagebuilder-disableblocks
mkdir -p app/code/Cadence/PageBuilderDisable && git clone https://github.com/cadencelabs/pagebuilder-disableblocks.git app/code/Cadence/PageBuilderDisable
php bin/magento setup:upgrade
Configure The Extension
- Then, configure the extension by navigating to Stores -> Configuration -> Cadence -> Page Builder Override -> Disable CMS Components
- Enter a comma (,) delimited list of block identifiers which you would like to disable Page Builder on
- Save Config
- Refresh All Caches
- You’re done!
How It Works
The extension works by extending (through a preference) the Page Builder configuration singleton. It then dynamically disables Page Builder if the URL indicates the given screen is an admin CMS block screen for one of the disabled block identifiers. We use the URL to determine this as Page Builder’s configuration is initialized well before the current block is determined:
// File app/code/Cadence/PageBuilderDisable/Model/Config.php
/**
* Returns config setting if page builder enabled
*
* @return bool
*/
public function isEnabled(): bool
{
if (parent::isEnabled()) {
$excludedBlocks = trim($this->scopeConfig->getValue(self::CONFIG_PATH_DISABLED_BLOCKS));
if (strlen($excludedBlocks) && $this->_isDisabledUrlCandidate()) {
$excludedBlocks = explode(",", $excludedBlocks);
foreach($excludedBlocks as $excludedBlock) {
if ($this->_isDisabledBlock($excludedBlock)) {
return false;
}
}
}
return true;
}
return false;
}
/**
* Determine if we should examine the URL further for exclusion of page builder
* @return bool
*/
protected function _isDisabledUrlCandidate()
{
$disableCandidateRegex = str_replace('{{id}}/', '', $this->disableBlockRegex);
return preg_match($disableCandidateRegex, $this->urlInterface->getCurrentUrl());
}
/**
* Examine the URL to determine if pagebuilder is disabled
* @param string $block
* @return bool
*/
protected function _isDisabledBlock(string $block)
{
try {
$blockModel = $this->blockRepository->getById($block);
// Create the url pattern for this specific block based on the primary key id
$urlPattern = str_replace("{{id}}", $blockModel->getId(), $this->disableBlockRegex);
// If it matches, return false
return preg_match($urlPattern, $this->urlInterface->getCurrentUrl());
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
// If that block id no longer exists, don't worry about it
return false;
}
return true;
}
Need help with Magento 2?
We’ve had a lot of experience building websites in Magento 2. If you need help, head over to the Cadence Labs contact page, or email us at [email protected].