You are here

function _rdfui_validate_terms in RDF Extensions 7.2

Sets a form error if predicates don't validate.

3 calls to _rdfui_validate_terms()
rdfui_admin_rdf_overview_form_validate in rdfui/rdfui.module
rdfui_form_field_ui_field_edit_form_validate in rdfui/rdfui.module
rdfui_form_node_type_form_validate in rdfui/rdfui.module

File

rdfui/rdfui.module, line 497

Code

function _rdfui_validate_terms($form_state, $field_name = '') {

  // If the field_name is NOT NULL, then this is a predicate. If it is NULL,
  // this is a type.
  $field_id = $field_name != NULL ? 'rdf_' . $field_name . '_predicates' : 'rdf_rdftype';

  // Validate terms.
  if ($terms = trim($form_state['values'][$field_id])) {
    $terms = rdfui_extract_curies($terms);
    $rdf_namespaces = module_invoke_all('rdf_namespaces');
    $errors = array();
    $warnings = array();
    foreach ($terms as $term) {

      // Ensure this is a CURIE.
      if (!preg_match(QNAME, $term)) {

        // @todo Add a page to the drupal docs about CURIE format and adding
        // namespaces. Then add a link to this error that says 'For more info'.
        $errors[] = t('Term %term must be in CURIE format.', array(
          '%term' => $term,
        ));
      }
      else {

        // Check the prefixes to ensure they are bound. If not, issue a warning.
        $term_parts = explode(':', $term);
        $prefix = $term_parts[0];
        if (!isset($rdf_namespaces[$prefix])) {
          $warnings[] = t('Term %term uses unmapped prefix %prefix. Please map the prefix in !rdf_publishing.', array(
            '%term' => $term,
            '%prefix' => $prefix,
            '!rdf_publishing' => l(t('RDF publishing settings'), 'admin/config/services/rdf/namespaces'),
          ));
        }
      }
    }
    if (!empty($errors)) {
      foreach ($errors as $error) {
        form_set_error($field_id, $error);
      }
    }
    if (!empty($warnings)) {
      foreach ($warnings as $warning) {
        drupal_set_message($warning, $type = 'warning');
      }
    }
  }
}