public static function PerformValidation::nodes in Node Accessibility 8
Performs validation on the given nodes and stores the results.
Parameters
array $nodes_or_nids: An array of node objects or node ids.
string|null $language: (optional) The language to use during validation
array|null $severity: (optional) An array of booleans representing the qual test display levels
array|null $standards: (optional) An array of standards to use when validating. This will override a node type specific standards.
Return value
array An array of all test failures, if any.
4 calls to PerformValidation::nodes()
- node_accessibility_node_insert in ./
node_accessibility.module - Implements hook_ENTITY_TYPE_insert().
- node_accessibility_node_update in ./
node_accessibility.module - Implements hook_ENTITY_TYPE_update().
- ValidateFormBase::submitForm in src/
Form/ ValidateFormBase.php - Form submission handler.
- ValidateNode::execute in src/
Plugin/ Action/ ValidateNode.php - Executes the plugin.
File
- src/
PerformValidation.php, line 32
Class
- PerformValidation
- Class PerformValidation.
Namespace
Drupal\node_accessibilityCode
public static function nodes(array $nodes_or_nids, $language = NULL, $severity = NULL, $standards = NULL) {
if (count($nodes_or_nids) == 0) {
return [];
}
$results = [];
$quail_standards = QuailApiSettings::get_standards();
$quail_methods = QuailApiSettings::get_validation_methods();
$type_settings = [];
$node_type_standards = $standards;
foreach ($nodes_or_nids as $node_or_nid) {
if (is_numeric($node_or_nid)) {
$node = Node::load($node_or_nid);
}
else {
$node = $node_or_nid;
}
if (!$node instanceof Node) {
continue;
}
$id_node = $node->nid->value;
$id_revision = $node->vid->value;
if (!isset($results[$id_node][$id_revision])) {
$results[$id_node][$id_revision] = [];
}
$node_type = $node
->getType();
if (!array_key_exists($node_type, $type_settings)) {
$type_settings[$node_type] = TypeSettingsStorage::loadAsArray($node_type);
}
if (is_null($standards)) {
$node_type_standards = $type_settings[$node_type]['standards'];
}
if (!empty($node_type_standards)) {
$node_view = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node, 'full', $language);
$rendered_node = \Drupal::service('renderer')
->render($node_view);
unset($node_view);
foreach ($node_type_standards as $standard_name) {
$results[$id_node][$id_revision] = array_merge($results[$id_node][$id_revision], QuailApiValidation::validate($rendered_node, $quail_standards[$standard_name], $severity));
}
unset($rendered_node);
}
if (isset($results[$id_node][$id_revision]['report'])) {
$database = FALSE;
if (!empty($type_settings[$node_type]['method']) && is_array($quail_methods) && array_key_exists('database', $quail_methods[$type_settings[$node_type]['method']])) {
$database = $quail_methods[$type_settings[$node_type]['method']]['database'];
}
if ($database && !empty($results[$id_node][$id_revision]['report'])) {
$no_failures = TRUE;
foreach ($results[$id_node][$id_revision]['report'] as $severity => $severity_results) {
if (isset($severity_results['total']) && $severity_results['total'] > 0) {
$no_failures = FALSE;
break;
}
}
if ($no_failures) {
ProblemsStorage::delete_node_problems($id_node, $id_revision);
}
else {
ProblemsStorage::save_node_problems($id_node, $id_revision, $results[$id_node][$id_revision]['report']);
}
}
}
unset($node);
}
return $results;
}