You are here

class ValidateNode in Node Accessibility 8

Perform accessibility validation on a node.

Plugin annotation


@Action(
  id = "node_accessibility_validate_action",
  label = @Translation("Perform Accessibility Validation on Node"),
  type = "node"
)

Hierarchy

Expanded class hierarchy of ValidateNode

File

src/Plugin/Action/ValidateNode.php, line 21

Namespace

Drupal\node_accessibility\Plugin\Action
View source
class ValidateNode extends ActionBase {

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {
    if (is_null($entity)) {
      return;
    }
    $id_node = $entity
      ->id();
    $id_revision = $entity
      ->id();
    $settings = TypeSettingsStorage::loadByNodeAsArray($id_node);
    if (is_null($id_revision)) {
      $results = PerformValidation::nodes([
        $id_node,
      ], NULL, NULL, $settings['standards']);
    }
    else {
      $results = PerformValidation::node_revisions([
        $id_revision => $id_node,
      ], NULL, NULL, $settings['standards']);
    }
    if (empty($settings['node_type'])) {
      return;
    }
    if (empty($settings['enabled']) || $settings['enabled'] == 'disabled') {
      return;
    }
    if (array_key_exists($id_node, $results) && !empty($results[$id_node])) {
      $severitys = QuailApiSettings::get_severity();
      $methods = QuailApiSettings::get_validation_methods();
      if ($settings['method'] == 'quail_api_method_manual' || $settings['method'] == 'quail_api_method_immediate') {

        // do not process validation action if not saving to the database.
        return;
      }
      $revision = reset($results[$id_node]);
      unset($results);
      if (empty($revision['report'])) {
        unset($revision);
        $markup = $this
          ->t('No accessibility violations have been detected.');
      }
      else {
        $reports = $revision['report'];
        $total = $revision['total'];
        unset($revision);
        if (empty($settings['format_results'])) {
          $format_results = \Drupal::config('quail_api.settings')
            ->get('filter_format');
        }
        else {
          $format_results = $settings['format_results'];
        }
        if (empty($settings['title_block'])) {
          $title_block = \Drupal::config('quail_api.settings')
            ->get('title_block');
        }
        else {
          $title_block = $settings['title_block'];
        }
        if (empty($title_block)) {
          $title_block = 'h3';
        }

        // the reason this is converted to markup is because the generated
        // markup is intended to be saved to the database. This is not a
        // cache, but a renderred copy of the data for archival and
        // validation purposes.
        $markup = '';
        foreach ($reports as $severity => $severity_results) {
          $theme_array = [
            '#theme' => 'quail_api_results',
            '#quail_severity_id' => $severity,
            '#quail_severity_array' => $severitys[$severity],
            '#quail_severity_results' => $severity_results,
            '#quail_markup_format' => $format_results,
            '#quail_title_block' => $title_block,
            '#quail_display_title' => TRUE,
            '#attached' => [
              'library' => [
                'node_accessibility/results-theme',
              ],
            ],
          ];
          $markup .= \Drupal::service('renderer')
            ->render($theme_array, FALSE);
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    return $object
      ->access('perform node accessibility validation', $account, $return_as_object);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionBase::executeMultiple public function Executes the plugin for an array of objects. Overrides ActionInterface::executeMultiple 3
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ValidateNode::access public function Checks object access. Overrides ActionInterface::access
ValidateNode::execute public function Executes the plugin. Overrides ExecutableInterface::execute