You are here

function context_ui_edit_name_validate in Context 6

Same name and namespace in other branches
  1. 6.3 context_ui/export_ui/context_export_ui.class.php \context_ui_edit_name_validate()
  2. 7.3 context_ui/export_ui/context_export_ui.class.php \context_ui_edit_name_validate()

Replacement for ctools_export_ui_edit_name_validate(). Allow dashes.

1 string reference to 'context_ui_edit_name_validate'
context_ui_form in context_ui/export_ui/context_export_ui.class.php
Generates the omnibus context definition editing form.

File

context_ui/export_ui/context_export_ui.class.php, line 250

Code

function context_ui_edit_name_validate($element, &$form_state) {
  $plugin = $form_state['plugin'];

  // Check for string identifier sanity
  if (!preg_match('!^[a-z0-9_-]+$!', $element['#value'])) {
    form_error($element, t('The export id can only consist of lowercase letters, underscores, dashes, and numbers.'));
    return;
  }

  // Check for name collision
  if (empty($form_state['item']->export_ui_allow_overwrite) && ($exists = ctools_export_crud_load($plugin['schema'], $element['#value']))) {
    form_error($element, t('A @plugin with this name already exists. Please choose another name or delete the existing item before creating a new one.', array(
      '@plugin' => $plugin['title singular'],
    )));
  }
}