You are here

function custom_pub_add_validate in Custom Publishing Options 6

Same name and namespace in other branches
  1. 7 custom_pub.admin.inc \custom_pub_add_validate()

Form validation function for add form.

File

./custom_pub.module, line 144
Adds the ability to add Custom publishing options to the node Add/Edit form.

Code

function custom_pub_add_validate($form, $form_state) {
  $types = variable_get('custom_pub_types', array());
  $type = array();
  $type['type'] = trim($form_state['values']['state_machine']);
  $type['name'] = check_plain(trim($form_state['values']['state']));
  $node = drupal_get_schema('node');
  if (isset($types[$type['type']])) {
    form_set_error('state_machine', t('The machine-readable name %type is already taken.', array(
      '%type' => $type->type,
    )));
  }
  if (!preg_match('!^[a-z0-9_]+$!', $type['type'])) {
    form_set_error('state_machine', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
  }

  // 'theme' conflicts with theme_node_form().
  // '0' is invalid, since elsewhere we check it using empty().
  if (in_array($type['type'], array_keys($node['fields'])) && !isset($types[$type['type']])) {
    form_set_error('state_machine', t("Invalid machine-readable name. That name is already taken by a database column. Please enter a name other than %invalid.", array(
      '%invalid' => $type['type'],
    )));
  }
  foreach ($types as $check) {
    if ($type['name'] == $check['name']) {
      form_set_error('state', t("Invalid Label. That Publishing Label is already taken. Please enter a label other than %invalid.", array(
        '%invalid' => $type['name'],
      )));
    }
  }
}