You are here

function date_tools_wizard_form_validate in Date 7.2

Same name and namespace in other branches
  1. 8 date_tools/date_tools.wizard.inc \date_tools_wizard_form_validate()
  2. 6.2 date_tools/date_tools.wizard.inc \date_tools_wizard_form_validate()
  3. 7.3 date_tools/date_tools.wizard.inc \date_tools_wizard_form_validate()
  4. 7 date_tools/date_tools.wizard.inc \date_tools_wizard_form_validate()

Form validation.

File

date_tools/date_tools.wizard.inc, line 140
The Date Wizard code.

Code

function date_tools_wizard_form_validate(&$form, &$form_state) {
  $bundle = $form_state['values']['bundle'];
  $field_name = 'field_' . $form_state['values']['field_name'];
  $args = array(
    ':field_name' => $field_name,
    ':bundle' => $bundle,
    ':entity_type' => 'node',
  );
  $query = "SELECT type FROM {node_type} WHERE type=:bundle";
  $existing_type = db_query($query, array(
    ':bundle' => $args[':bundle'],
  ))
    ->fetchField();
  $query = "SELECT field_name FROM {field_config_instance} WHERE field_name=:field_name AND bundle=:bundle AND entity_type=:entity_type";
  $existing_instance = db_query($query, $args)
    ->fetchField();
  if ($existing_type) {
    drupal_set_message(t('This content type name already exists, adding new field to existing content type.'));
  }
  if (!preg_match('!^[a-z0-9_]+$!', $bundle)) {
    form_set_error('bundle', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
  }
  if (!empty($form_state['values']['calendar']) && !empty($form_state['values']['blocks']) && strlen($bundle) > 12) {
    form_set_error('bundle', t('The content type name must be no more than 12 characters long when using it to create a calendar and blocks.'));
  }
  if ($existing_instance) {
    form_set_error('field_name', t('This field name already exists.'));
  }
  if (strlen($field_name) > 32) {
    form_set_error('field_name', t('The field name must be no more than 26 characters long.'));
  }
  if (!date_has_time($form_state['values']['granularity']) && $form_state['values']['tz_handling'] != 'none') {
    form_set_error('tz_handling', t('Timezone handling must be none for granularity without time.'));
  }
}