I am trying to override the file app/code/Magento/Theme/view/frontend/layouts.xml
I do not want to extend this file, I want to override it so that some of the base design layouts are not available in the admin.
Instead of overriding layouts.xml
I ended up doing the following
Create a new Module
: app/code/<Vendor>/Cms
Create the file: 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;
}
}
This will get the $options
and then remove any that are in the $remove
array based on the $option['value']
In order to have this run, you need to override part of app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml
To do this create the file: 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>
We are now telling that ui_component field to use our new Model to retrieve the options.
You can also create the file 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>
Simply put your layout file inside "/override/base" folder.
In your case your layout file will be located in "theme_or_module_folder/Magento_Theme/layout/override/base/layouts.xml"
For more information see http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-override.html
app/code/Magento/Theme/view/frontend/layouts/*.xml
. This file is outside of that folder. I tried adding the file as you described and I get the following error: Overriding view file '/var/www/html/app/design/frontend/vendor/theme/Magento_Theme/layout/override/base/layouts.xml' does not match to any of the files
Commented
Dec 11, 2017 at 23:13