1.20.x layout.class.inc | Layout::__construct(array $config = array()) |
Constructor for a Layout class.
Parameters
array $config: An array of configuration data.
File
- modules/
layout/ includes/ layout.class.inc, line 203 - Class for loading, modifying, and executing a layout.
Class
- Layout
- @file Class for loading, modifying, and executing a layout.
Code
function __construct(array $config = array()) {
foreach ($config as $property => $property_value) {
$this->{$property} = $property_value;
}
// Specify default settings.
$this->settings += array(
'title' => '',
'title_display' => LAYOUT_TITLE_DEFAULT,
'title_block' => NULL,
);
// Adjust for the renaming of "layout" to "layout_template".
// See https://github.com/backdrop/backdrop-issues/issues/998
// @todo: Remove in 2.x.
if (isset($this->layout) && !isset($this->layout_template)) {
$this->layout_template = $this->layout;
unset($this->layout);
}
// Set the storage type.
if (isset($config['module'])) {
if (empty($config['storage']) || $config['storage'] == LAYOUT_STORAGE_DEFAULT) {
$this->storage = LAYOUT_STORAGE_DEFAULT;
}
else {
$this->storage = LAYOUT_STORAGE_OVERRIDE;
}
}
else {
$this->storage = LAYOUT_STORAGE_NORMAL;
}
// Convert all stored contexts, conditions, and relationships to their
// handler equivalents.
$handlers = array(
// Items are key => handler_type.
'content' => 'block',
'conditions' => 'layout_access',
'contexts' => 'layout_context',
'relationships' => 'layout_relationship',
);
foreach ($handlers as $property_key => $plugin_type) {
foreach ($this->{$property_key} as $plugin_type_key => $plugin_data) {
// Set the storage property for contexts stored in config.
if ($property_key == 'contexts') {
$plugin_data['data']['storage'] = TRUE;
}
$this->{$property_key}[$plugin_type_key] = layout_create_handler($plugin_type, $plugin_data['plugin'], $plugin_data['data']);
}
}
// Ensure contexts is always set to an array.
if (is_null($this->contexts)) {
$this->contexts = array();
}
}