Let the platform do the work

Manipulating Layouts Programmatically

Overview

How to manipulate and merge layouts programmatically.

Note: This customization is only applicable for modules in backward compatibility mode.

The ParserFactory

The ParserFactory can be used to manipulate layouts such as editviewdefs or detailviewdefs. This is a handy when creating custom plugins and needing to merge changes into an existing layout. The following example will demonstrate how to add a button to the detail view:

  <?php

//Instantiate the parser factory for the Accounts DetailView.
require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
$parser = ParserFactory::getParser('detailview', 'Accounts');

//Button to add
$button = array(
    'customCode'=>'<input type="button" name="customButton" value="Custom Button">'
);

//Add button into the parsed layout
array_push($parser->_viewdefs['templateMeta']['form']['buttons'], $button);

//Save the layout
$parser->handleSave(false);