719-286-0751 info@cadence-labs.com

Magento 2 Commerce Cloud – Disable Page Builder For Certain Blocks

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

  1. Then, configure the extension by navigating to Stores -> Configuration -> Cadence -> Page Builder Override -> Disable CMS Components
  2. Enter a comma (,) delimited list of block identifiers which you would like to disable Page Builder on
  3. Save Config
  4. Refresh All Caches
  5. 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;
    }
Alan Barber is the Lead Web Developer at Cadence Labs and a Magento 2 Certified Professional Developer.

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 info@cadence-labs.com

Submit a Comment

Your email address will not be published. Required fields are marked *

Install our webapp on your iPhone! Tap and then Add to homescreen.
Share This