1 layout.admin.inc | layout_template_toggle_enabled($template_name, $status) |
Menu callback; Enable or disable a layout template.
File
- core/
modules/ layout/ layout.admin.inc, line 2370 - Admin page callbacks for the Layout module.
Code
function layout_template_toggle_enabled($template_name, $status) {
if (backdrop_get_token('layout-template-' . $template_name) !== $_GET['token']) {
return MENU_ACCESS_DENIED;
}
$template_info = layout_get_layout_template_info($template_name);
if (!$template_info) {
return MENU_NOT_FOUND;
}
$config = config('layout.settings');
$data = $config->get();
$errors = FALSE;
if (!$status) {
if (!in_array($template_name, $data['excluded_templates'])) {
$data['excluded_templates'][] = $template_name;
}
// Check which layout templates are in use.
foreach (layout_load_all() as $layout) {
$info = layout_get_layout_template_info($layout->layout_template);
if (in_array($layout->layout_template, $data['excluded_templates'])) {
$errors = TRUE;
break;
}
}
if ($errors) {
backdrop_set_message(t('The "@layout" layout template is currently in use and may not be disabled.', array('@layout' => $info['title'])), 'error');
}
else {
backdrop_set_message(t('Layout template "@title" disabled.', array('@title' => $template_info['title'])));
}
}
else {
$data['excluded_templates'] = array_diff($data['excluded_templates'], array($template_name));
backdrop_set_message(t('Layout template "@title" enabled.', array('@title' => $template_info['title'])));
}
if (!$errors) {
$config->setData($data);
$config->save();
}
backdrop_goto('admin/structure/layouts/settings');
}