function panels_bootstrap_convert_settings in Panels Bootstrap Layout Builder 7
Same name and namespace in other branches
- 7.3 plugins/layouts/bootstrap/bootstrap.inc \panels_bootstrap_convert_settings()
Convert settings from old style to new, or provide defaults for empty settings.
Parameters
<type> $settings:
8 calls to panels_bootstrap_convert_settings()
- panels_ajax_bootstrap_edit_add in plugins/
layouts/ bootstrap/ bootstrap.inc - AJAX responder to add a new row, column or region to a bootstrap layout.
- panels_ajax_bootstrap_edit_remove in plugins/
layouts/ bootstrap/ bootstrap.inc - AJAX responder to remove an existing row, column or region from a bootstrap layout.
- panels_ajax_bootstrap_edit_resize in plugins/
layouts/ bootstrap/ bootstrap.inc - AJAX responder to store resize information when the user adjusts the splitter.
- panels_ajax_bootstrap_edit_reuse in plugins/
layouts/ bootstrap/ bootstrap.inc - AJAX form to bring up the "reuse" modal.
- panels_ajax_bootstrap_edit_settings in plugins/
layouts/ bootstrap/ bootstrap.inc - AJAX responder to edit bootstrap settings for an item.
File
- plugins/
layouts/ bootstrap/ bootstrap.inc, line 86
Code
function panels_bootstrap_convert_settings(&$settings, &$layout) {
// This indicates that this is a layout that they used the checkbox
// on. The layout is still 'bootstrap' but it's actually pointing
// to another stored one and we have to load it.
if (!empty($settings['layout'])) {
$layout = panels_get_layout('bootstrap:' . $settings['layout']);
}
if (!empty($layout['layout'])) {
$settings = $layout['layout']->settings;
if ($settings) {
return $settings;
}
}
if (empty($settings)) {
// set up a default
$settings = array(
'items' => array(
// The 'canvas' is a special row that does not get rendered
// normally, but is used to contain the columns.
'canvas' => array(
'type' => 'row',
'contains' => 'column',
'children' => array(
'main',
),
'parent' => NULL,
),
'main' => array(
'type' => 'column',
'bootstrap_class' => 'span12',
'grid_type' => 'row',
'children' => array(
'main-row',
),
'parent' => 'canvas',
),
'main-row' => array(
'type' => 'row',
'contains' => 'region',
'children' => array(
'center',
),
'parent' => 'main',
),
'center' => array(
'type' => 'region',
'title' => t('Center'),
'bootstrap_class' => 'span12',
'grid_type' => 'row',
'parent' => 'main-row',
),
),
);
}
else {
if (!isset($settings['items'])) {
// Convert an old style bootstrap to a new style bootstrap.
$old = $settings;
$settings = array();
$settings['items']['canvas'] = array(
'type' => 'row',
'contains' => 'column',
'children' => array(),
'parent' => NULL,
);
// add the left sidebar column, row and region if it exists.
if (!empty($old['sidebars']['left'])) {
$settings['items']['canvas']['children'][] = 'sidebar-left';
$settings['items']['sidebar-left'] = array(
'type' => 'column',
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'children' => array(
'sidebar-left-row',
),
'parent' => 'canvas',
);
$settings['items']['sidebar-left-row'] = array(
'type' => 'row',
'contains' => 'region',
'children' => array(
'sidebar_left',
),
'parent' => 'sidebar-left',
);
$settings['items']['sidebar_left'] = array(
'type' => 'region',
'title' => t('Left sidebar'),
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'parent' => 'sidebar-left-row',
);
}
$settings['items']['canvas']['children'][] = 'main';
if (!empty($old['sidebars']['right'])) {
$settings['items']['canvas']['children'][] = 'sidebar-right';
$settings['items']['sidebar-right'] = array(
'type' => 'column',
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'children' => array(
'sidebar-right-row',
),
'parent' => 'canvas',
);
$settings['items']['sidebar-right-row'] = array(
'type' => 'row',
'contains' => 'region',
'children' => array(
'sidebar_right',
),
'parent' => 'sidebar-right',
);
$settings['items']['sidebar_right'] = array(
'type' => 'region',
'title' => t('Right sidebar'),
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'parent' => 'sidebar-right-row',
);
}
// Add the main column.
$settings['items']['main'] = array(
'type' => 'column',
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'children' => array(),
'parent' => 'canvas',
);
// Add rows and regions.
for ($row = 1; $row <= intval($old['rows']); $row++) {
// Create entry for the row
$settings['items']["row_{$row}"] = array(
'type' => 'row',
'contains' => 'region',
'children' => array(),
'parent' => 'main',
);
// Add the row to the parent's children
$settings['items']['main']['children'][] = "row_{$row}";
for ($col = 1; $col <= intval($old["row_{$row}"]['columns']); $col++) {
// Create entry for the region
$settings['items']["row_{$row}_{$col}"] = array(
'type' => 'region',
'bootstrap_class' => 'span1',
'grid_type' => 'row',
'parent' => "row_{$row}",
);
// Add entry for the region to the row's children
$settings['items']["row_{$row}"]['children'][] = "row_{$row}_{$col}";
// Apply the proper title to the region
if (!empty($old["row_{$row}"]['names'][$col - 1])) {
$settings['items']["row_{$row}_{$col}"]['title'] = $old["row_{$row}"]['names'][$col - 1];
}
else {
$settings['items']["row_{$row}_{$col}"]['title'] = t("Row @row, Column @col", array(
'@row' => $row,
'@col' => $col,
));
}
}
}
}
else {
if (isset($settings['canvas'])) {
// Convert the old 'canvas' to the new canvas row.
$settings['items']['canvas'] = array(
'type' => 'row',
'contains' => 'column',
'children' => $settings['canvas'],
'parent' => NULL,
);
unset($settings['canvas']);
}
}
}
}