You are here

function ds_field_ui_layout_change_validate in Display Suite 7

Validate callback: make sure old regions can not be mapped more than once.

File

./ds.field_ui.inc, line 428
Field UI functions for Display Suite.

Code

function ds_field_ui_layout_change_validate($form, &$form_state) {
  $layout = $form['#old_layout'];
  $new_layout = $form['#new_layout'];
  $mappings = array();
  foreach ($new_layout['regions'] as $new_region => $region_title) {
    $values = $form_state['values']['ds_' . $new_region];
    foreach ($values as $old_region) {
      if (!isset($mappings[$old_region])) {
        $mappings[$old_region] = $old_region;
        if (!isset($mappings['new'][$new_region])) {
          $mappings['new'][$new_region] = array();
        }
        $mappings['new'][$new_region][$old_region] = $old_region;
      }
      else {
        form_set_error('ds_' . $new_region, t('You can not map old regions into multiple new regions.'));
        break;
      }
    }
  }

  // Save the mappings so we can re-use in the submit callback.
  $form_state['mappings'] = isset($mappings['new']) ? $mappings['new'] : array();
}