Magento2 Magento 2删除布局选项

Magento2 Magento 2删除布局选项,magento2,Magento2,我正在Magento 2中创建一个自定义主题。 在页面、类别、产品等的“设计”选项卡中选择布局时,我有以下选项: 1列 带左栏的2列 带右栏的2列 3列 我已经知道如何将自己的布局添加到这组选项中 我的问题是:如何删除(或在紧急情况下隐藏)不需要的核心布局?例如,我的主题根本不需要3列布局,因此我不希望这成为一个选项。好的,下面是您需要做的: 创建新的模块:app/code//Cms 您需要确保模块已正确注册 然后创建文件:app/code//Cms/Model/PageLayout.php &

我正在Magento 2中创建一个自定义主题。 在页面、类别、产品等的“设计”选项卡中选择布局时,我有以下选项:

  • 1列
  • 带左栏的2列
  • 带右栏的2列
  • 3列
  • 我已经知道如何将自己的布局添加到这组选项中


    我的问题是:如何删除(或在紧急情况下隐藏)不需要的核心布局?例如,我的主题根本不需要3列布局,因此我不希望这成为一个选项。

    好的,下面是您需要做的:

    创建新的
    模块
    app/code//Cms

    您需要确保
    模块
    已正确注册

    然后创建文件:
    app/code//Cms/Model/PageLayout.php

    <?php
    
    namespace <Vendor>\Cms\Model;
    
    use Magento\Cms\Model\Page\Source\PageLayout as BasePageLayout;
    
    class PageLayout extends BasePageLayout{
    
        public function toOptionArray()
        {
            $options = parent::toOptionArray();
            $remove = [
                "empty",
                "1column",
                "2columns-left",
                "2columns-right",
                "3columns",
            ];
    
            foreach($options as $key => $layout){
                if(in_array($layout["value"], $remove)){
                    unset($options[$key]);
                }
            }
    
            return $options;
        }
    }
    
    我们现在告诉ui_组件字段使用我们的新模型来检索选项

    您还可以创建文件
    app/code//Cms/view/adminhtml/ui\u component/Cms\u page\u listing.xml

    <?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="design">
            <field name="page_layout">
                <argument name="data" xsi:type="array">
                    <item name="options" xsi:type="object"><Vendor>\Cms\Model\PageLayout</item>
                </argument>
            </field>
        </fieldset>
    </form>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
        <columns name="cms_page_columns">
            <column name="page_layout">
                <argument name="data" xsi:type="array">
                    <item name="options" xsi:type="object"><Vendor>\Cms\Model\PageLayout</item>
                </argument>
            </column>
        </columns>
    </listing>
    
    
    \Cms\Model\PageLayout
    
    除了此解决方案不会从某些部分(如类别或产品设计设置-但这只是更新此解决方案中的adminhtml/ui\u组件布局)中删除默认页面布局选项之外,此解决方案工作正常。因此,我不明白,为什么这个答案不被标记为正确?