You are here

function ds_edit_view_mode_form_validate in Display Suite 7

Same name and namespace in other branches
  1. 7.2 modules/ds_ui/includes/ds.view_modes.inc \ds_edit_view_mode_form_validate()

Validates the view mode submission form generated by ds_edit_view_mode_form().

File

./ds.view_modes.inc, line 134
Administrative functions for managing view modes for every entity.

Code

function ds_edit_view_mode_form_validate($form, &$form_state) {
  $view_mode = new stdClass();
  $view_mode->view_mode = $form_state['values']['view_mode'];
  $view_mode->label = $form_state['values']['name'];
  $reserved = array();
  $entities = $form_state['values']['entities'];
  foreach ($entities as $key => $value) {
    if ($key !== $value) {
      unset($entities[$key]);
    }
    else {
      $reserved += ds_entity_view_modes($key);
    }
  }
  if (array_key_exists($view_mode->view_mode, $reserved) && !isset($form_state['values']['existing'])) {
    form_set_error('type', t('The machine-readable name %view_mode is reserved.', array(
      '%view_mode' => $view_mode->view_mode,
    )));
  }
  else {
    $view_mode->entities = $entities;
    $form_state['view_mode'] = $view_mode;
  }
}