function ctools_export_ui_edit_name_validate

Validate that an export item name is acceptable and unique during add.

1 call to ctools_export_ui_edit_name_validate()
ctools_export_ui::edit_finish_validate in plugins/export_ui/ctools_export_ui.class.php
Perform a final validation check before allowing the form to be finished.

File

plugins/export_ui/ctools_export_ui.class.php, line 1422

Code

function ctools_export_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, 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'],
    )));
  }
}