You are here

function node_accessibility_perform_validation in Node Accessibility 7

Performs validation on the given nodes and stores the results.

Parameters

array $nodes_or_nids: An array of node objects or node ids.

array $vids: (optional) The an array vids to use during validation, with the following structure:

  • nid: an array of vids With the array key being the node id.

    • example: $vids = array('1' => array('2', '3', '4')) such '1' is the

    node id and 2, 3, and 4 are the vids for node 1.

string|null $language: (optional) The language to use during validation

array|null $display_level: (optional) An array of booleans representing the qual test display levels (defaults to quail_api_create_quail_display_level_array()).

Return value

array An array of all test failures, if any.

4 calls to node_accessibility_perform_validation()
node_accessibility_accessibility_tab_page in includes/pages.inc
Provides the accessibility tab page.
node_accessibility_drush_callback_validate in ./node_accessibility.drush.inc
Drush command callback.
node_accessibility_operation_validate in ./node_accessibility.module
Perform validation on any number of nodes.
node_accessibility_validate_action in ./node_accessibility.module
Performs accessibility validation on a given node.

File

./node_accessibility.module, line 486
Module file for the node accessibility project.

Code

function node_accessibility_perform_validation($nodes_or_nids, $vids = array(), $language = NULL, $display_level = NULL) {
  if (!is_array($nodes_or_nids)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('node_or_nids');
    }
    return array();
  }
  if (!is_array($vids)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('vids');
    }
    return array();
  }
  if (count($nodes_or_nids) == 0) {
    return array();
  }
  $node_type_settings = node_accessibility_load_node_type_settings();
  $results = array();
  $standards = quail_api_get_standards(NULL, 'snippet');
  foreach ($nodes_or_nids as $node_or_nid) {
    if (is_object($node_or_nid)) {
      $node = $node_or_nid;
    }
    else {
      $node = node_load($node_or_nid);
      if (!is_object($node)) {
        if (class_exists('cf_error')) {
          cf_error::invalid_variable('node', "Unable to load the node with the following node id: :nid.", array(
            ':nid' => $node_or_nid,
          ));
        }
        continue;
      }
    }
    $node_settings = FALSE;
    if (isset($node_type_settings[$node->type])) {
      $node_settings = $node_type_settings[$node->type];
    }
    if (array_key_exists($node->nid, $vids) && !empty($vids[$node->nid])) {
      $revisions = $vids[$node->nid];
    }
    else {
      $revisions = array(
        $node->vid,
      );
    }
    $results[$node->nid] = array();
    foreach ($revisions as $rid) {
      $results[$node->nid][$rid] = array();
      if ($node->vid == $rid) {
        $revision = $node;
      }
      else {
        $revision = node_load($node->nid, $rid);
        if (!is_object($revision)) {
          if (class_exists('cf_error')) {
            cf_error::invalid_variable('revision', "Unable to load the node revision with the node id of :nid and the revision id of :rid.", array(
              ':nid' => $node->nid,
              ':rid' => $rid,
            ));
          }
          continue;
        }
      }
      if (is_array($node_settings)) {
        $node_view = node_view($revision, 'full', $language);
        $rendered_node = drupal_render($node_view);
        unset($node_view);
        if (!empty($node_settings['standards'])) {
          foreach ($node_settings['standards'] as $standard_name) {
            $results[$revision->nid][$rid] = array_merge($results[$revision->nid][$rid], quail_api_validate_markup($rendered_node, $standards[$standard_name], $display_level));
            if (module_exists('rules')) {
              rules_invoke_event('node_accessibility_after_validating', $revision, $results[$node->nid][$rid]);
            }
          }
        }
      }
    }
  }
  return $results;
}