You are here

function date_tools_wizard_form_validate in Date 7

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.2 date_tools/date_tools.wizard.inc \date_tools_wizard_form_validate()

File

date_tools/date_tools.wizard.inc, line 124

Code

function date_tools_wizard_form_validate(&$form, &$form_state) {
  $bundle = $form_state['values']['bundle'];
  $field_name = 'field_' . $form_state['values']['field_name'];
  $existing_type = db_query("SELECT type FROM {node_type} WHERE type=:bundle", array(
    ':bundle' => $bundle,
  ))
    ->fetchField();
  $existing_instance = db_query("SELECT field_name FROM {field_config_instance} WHERE field_name=:field_name AND bundle=:bundle AND entity_type=:entity_type", array(
    ':field_name' => $field_name,
    ':bundle' => $bundle,
    ':entity_type' => 'node',
  ))
    ->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 ($existing_instance) {
    form_set_error('field_name', t('This field name already exists.'));
  }
  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.'));
  }
}