You are here

function features_export_form_validate_field in Features 7

Same name and namespace in other branches
  1. 6 features.admin.inc \features_export_form_validate_field()
  2. 7.2 features.admin.inc \features_export_form_validate_field()

Render API callback: Validates a project field.

This function is assigned as an #element_validate callback in features_export_form().

1 string reference to 'features_export_form_validate_field'
features_export_form in ./features.admin.inc
Form constructor for features export form.

File

./features.admin.inc, line 174
@todo.

Code

function features_export_form_validate_field($element, &$form_state) {
  switch ($element['#name']) {
    case 'module_name':
      if (!preg_match('!^[a-z0-9_]+$!', $element['#value'])) {
        form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
      }
      else {
        if (empty($element['#default_value']) && features_get_info('module', $element['#value'])) {
          form_error($element, t('A module by the name @name already exists on your site. Please choose a different name.', array(
            '@name' => $element['#value'],
          )));
        }
      }
      break;
    case 'project_status_url':
      if (!empty($element['#value']) && !valid_url($element['#value'])) {
        form_error($element, t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array(
          '%url' => $element['#value'],
        )));
      }
      break;
    case 'version':
      preg_match('/^(?P<core>\\d+\\.x)-(?P<major>\\d+)\\.(?P<patch>\\d+)-?(?P<extra>\\w+)?$/', $element['#value'], $matches);
      if (!empty($element['#value']) && !isset($matches['core'], $matches['major'])) {
        form_error($element, t('Please enter a valid version with core and major version number. Example: @example', array(
          '@example' => '6.x-1.0',
        )));
      }
      break;
  }
}