You are here

function node_accessibility_operation_validate in Node Accessibility 7

Perform validation on any number of nodes.

Only nodes that have accessibility enabled will be validated in this way. All other nodes are silently ignored.

Parameters

array $nids: An array of node ids

1 string reference to 'node_accessibility_operation_validate'
node_accessibility_node_operations in ./node_accessibility.module
Implements hook_node_operations().

File

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

Code

function node_accessibility_operation_validate($nids) {
  $nodes = node_load_multiple($nids);
  $node_type_settings = node_accessibility_load_node_type_settings();
  $result = TRUE;
  foreach ($nodes as $key => $node) {
    if (!is_object($node)) {
      continue;
    }
    if (!array_key_exists($node->type, $node_type_settings)) {
      continue;
    }
    if ($node_type_settings[$node->type] === FALSE) {
      continue;
    }
    $methods = quail_api_get_validation_methods(NULL);
    $database = FALSE;
    $node_settings = $node_type_settings[$node->type];
    if (!empty($node_settings['method']) && is_array($methods) && array_key_exists('database', $methods[$node_settings['method']])) {
      $database = $methods[$node_settings['method']]['database'];
    }
    $results = node_accessibility_perform_validation(array(
      $node,
    ), array(), NULL, NULL);
    if (isset($results[$node->nid][$node->vid]['report'])) {
      $reports = $results[$node->nid][$node->vid]['report'];
      unset($results);
      if ($database && !empty($reports)) {
        $no_failures = TRUE;
        foreach ($reports as $severity => $severity_results) {
          if (isset($severity_results['total']) && $severity_results['total'] > 0) {
            $no_failures = FALSE;
            break;
          }
        }
        if ($no_failures) {
          node_accessibility_delete_node_problems($node->nid, $node->vid);
        }
        else {
          node_accessibility_save_node_problems($node->nid, $node->vid, $reports);
        }
      }
    }
    else {
      $result = FALSE;
    }
  }
  if ($result) {
    drupal_set_message(t("The validation has been performed."));
  }
  else {
    drupal_set_message(t("Unable to perform the validation, something went wrong."), 'error');
  }
}