Overriding Layouts
Overview
This page explains how to override a stock layout component. For this example, we will extend the stock record view and create a custom view named "my-record" that will be used in our record layout's override. This example involves two steps:
These steps are explained in the following sections.
Overriding the Layout
First, copy ./clients/base/layouts/record/record.php
to ./custom/clients/base/layouts/record/record.php
. Once copied, modify the following line from:
'view' => 'record',
'view' => 'my-record',
That line will change the record layout from using the base record.js view, ./clients/base/views/record/record.js
, to instead use a custom view that we will create in ./custom/clients/base/views/my-record/my-record.js
. At this point, the custom layout override should be very similar to the example below:
./custom/clients/base/layouts/record/record.php
<?php
$viewdefs['base']['layout']['record'] = [
'components' => [
[
'layout' => [
'type' => 'default',
'name' => 'sidebar',
'components' => [
[
'layout' => [
'type' => 'base',
'name' => 'main-pane',
'css_class' => 'main-pane overflow-scroll span8',
'components' => [
[
'view' => 'my-record',
'primary' => true,
],
[
'layout' => 'extra-info',
],
[
'layout' => [
'type' => 'filterpanel',
'css_class' => 'subpanels-container',
'last_state' => [
'id' => 'record-filterpanel',
'defaults' => [
'toggle-view' => 'subpanels',
],
],
'refresh_button' => true,
'availableToggles' => [
[
'name' => 'subpanels',
'icon' => 'sicon-list-view',
'label' => 'LBL_DATA_VIEW',
],
[
'name' => 'list',
'icon' => 'sicon-list-view',
'label' => 'LBL_LISTVIEW',
],
[
'name' => 'activitystream',
'icon' => 'sicon-clock',
'label' => 'LBL_ACTIVITY_STREAM',
],
],
'components' => [
[
'layout' => 'filter',
'xmeta' => [
'layoutType' => '',
],
'loadModule' => 'Filters',
],
[
'view' => 'filter-rows',
],
[
'view' => 'filter-actions',
],
[
'layout' => 'activitystream',
'context' => [
'module' => 'Activities',
],
],
[
'layout' => 'subpanels',
],
],
],
],
],
],
],
[
'layout' => [
'type' => 'tabbed-layout',
'name' => 'dashboard-pane',
'label' => 'LBL_DASHBOARD',
'css_class' => 'dashboard-pane',
'notabs' => true,
'components' => [
[
'layout' => [
'type' => 'base',
'label' => 'LBL_DASHBOARD',
'css_class' => 'dashboard-pane',
'components' => [
[
'layout' => [
'label' => 'LBL_DASHBOARD',
'type' => 'dashboard',
'last_state' => [
'id' => 'last-visit',
],
],
'context' => [
'forceNew' => true,
'module' => 'Home',
],
'loadModule' => 'Dashboards',
],
],
],
],
],
],
],
[
'layout' => [
'type' => 'tabbed-layout',
'name' => 'preview-pane',
'label' => 'LBL_PREVIEW',
'css_class' => 'preview-pane',
'notabs' => true,
'components' => [
[
'layout' => 'preview',
'xmeta' => [
'editable' => true,
],
],
],
],
],
],
],
],
],
];
Extending the View
For this example, we will extend the stock record view and create a custom view named my-record that will be used in our record layouts override.
./custom/clients/base/views/my-record/my-record.js
({
extendsFrom: 'RecordView',
initialize: function (options) {
this._super("initialize", [options]);
//log this point
console.log("**** Override called");
}
})
Once the files are in place, navigate to Admin > Repair > Quick Repair and Rebuild.