我正在尝试覆盖文件app / code / Magento / Theme / view / frontend / layouts.xml
我不想扩展此文件,我想覆盖它,以便管理员无法使用某些基本设计布局。
答案 0 :(得分:1)
而不是覆盖layouts.xml
我最终做了以下
制作新的Module
:app/code/<Vendor>/Cms
创建文件:app/code/<Vendor>/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;
}
}
这将获得$options
,然后根据$remove
$option['value']
数组中的所有内容
要进行此操作,您需要覆盖app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml
为此,请创建文件:app/code/<Vendor>/Cms/view/adminhtml/ui_component/cms_page_form.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>
我们现在告诉ui_component字段使用我们的新模型来检索选项。
您还可以创建文件app/code/<Vendor>/Cms/view/adminhtml/ui_component/cms_page_listing.xml
<?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>