1.20.x layout.admin.inc layout_settings_page_validate(&$form, &$form_state)

Validation for layout settings page.

Ensures that active layouts are not disabled while in use.

File

modules/layout/layout.admin.inc, line 2963
Admin page callbacks for the Layout module.

Code

function layout_settings_page_validate(&$form, &$form_state) {
  $options = array_keys($form_state['values']['templates']);
  $included = array_values($form_state['values']['templates']);
  $excluded = array_unique(array_diff($options, $included));
  $form_state['excluded_templates'] = array_values(array_merge($excluded, $form_state['hidden_templates']));

  // Ensure all layouts are not disabled.
  if (empty($form_state['values']['templates'])) {
    form_set_error('templates', t('At least one layout template must be enabled.'));
  }

  // 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, $excluded)) {
      form_set_error('templates][' . $layout->layout_template, t('The "@layout" layout template is currently in use and may not be disabled.', array('@layout' => $info['title'])));
    }
  }
}