abstract class ValidateFormBase in Node Accessibility 8
Base Form controller for the node_accessibility entity validate forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\node_accessibility\Form\ValidateFormBase
Expanded class hierarchy of ValidateFormBase
2 files declare their use of ValidateFormBase
- ValidateForm.php in src/
Form/ ValidateForm.php - ValidateRevisionForm.php in src/
Form/ ValidateRevisionForm.php
File
- src/
Form/ ValidateFormBase.php, line 20
Namespace
Drupal\node_accessibility\FormView source
abstract class ValidateFormBase extends FormBase {
/**
* The node validation settings.
*
* @var \Drupal\node_accessibility\TypeSettingsStorage
*/
protected $nodeSettings;
/**
* The node ID.
*
* @var int
*/
protected $nodeId;
/**
* The node revision ID.
*
* @var int
*/
protected $nodeRevisionId;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Class Constructor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->nodeSettings = NULL;
$this->nodeId = NULL;
$this->nodeRevisionId = NULL;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* Class Destructor.
*/
public function __destruct() {
$this->nodeSettings = NULL;
$this->nodeId = NULL;
$this->nodeRevisionId = NULL;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $node = NULL, $node_revision = NULL) {
$this->nodeId = $node;
$this->nodeRevisionId = $node_revision;
$this->nodeSettings = TypeSettingsStorage::loadByNode($this->nodeId);
$form['fieldset_results'] = [
'#type' => 'details',
'#title' => $this
->t('Validation Results'),
'#tree' => TRUE,
'#open' => TRUE,
];
$form['fieldset_results']['value_results'] = [
'#markup' => '',
];
$existing_value_results = $form_state
->get('fieldset_results][value_results');
if (is_null($existing_value_results)) {
$form['fieldset_results']['value_results']['#markup'] = 'There are no validation results available for this node.';
$settings = TypeSettingsStorage::loadByNodeAsArray($node);
$method = QuailApiSettings::get_validation_methods($settings['method']);
if (is_array($method) && $method['database']) {
$node_object = Node::load($node);
if (!is_null($node_revision) && $node_object->vid->value != $node_revision) {
$entity_type = $node_object
->getEntityTypeId();
$node_object = $this->entityTypeManager
->getStorage($entity_type)
->loadRevision($node_revision);
unset($entity_type);
}
$existing_database_results = ProblemsStorage::load_problems([
'nid' => $node,
'vid' => $node_object->vid->value,
]);
if (!empty($existing_database_results)) {
unset($form['fieldset_results']['value_results']['#markup']);
$severitys = QuailApiSettings::get_severity();
$restructured_results = ProblemsStorage::restructure_results($node, $node_object->vid->value, $severitys);
foreach ($restructured_results as $severity => $severity_results) {
$form['fieldset_results']['value_results'][$severity] = [
'#theme' => 'quail_api_results',
'#quail_severity_id' => $severity,
'#quail_severity_array' => $severitys[$severity],
'#quail_severity_results' => $severity_results,
'#quail_markup_format' => $settings['format_results'],
'#quail_title_block' => $settings['title_block'],
'#quail_display_title' => TRUE,
'#attached' => [
'library' => [
'node_accessibility/results-theme',
],
],
];
}
}
}
}
else {
$form['fieldset_results']['value_results']['#markup'] = $existing_value_results;
}
$form['actions'] = [
'#type' => 'actions',
];
if (\Drupal::currentUser()
->hasPermission('perform node accessibility validation')) {
$form['actions']['submit_validate'] = array(
'#type' => 'submit',
'#value' => $this
->t('Validate'),
);
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if (!\Drupal::currentUser()
->hasPermission('perform node accessibility validation')) {
$form_state
->setErrorByName('actions][submit_validate', $this
->t('You are not authorized to perform validation at this time.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if (empty($this->nodeId)) {
return;
}
if (is_null($this->nodeSettings)) {
$this->nodeSettings = TypeSettingsStorage::loadByNode($this->nodeId);
}
if (is_null($this->nodeRevisionId)) {
$results = PerformValidation::nodes([
$this->nodeId,
], NULL, NULL, $this->nodeSettings
->getStandards());
}
else {
$results = PerformValidation::node_revisions([
$this->nodeRevisionId => $this->nodeId,
], NULL, NULL, $this->nodeSettings
->getStandards());
}
if (empty($this->nodeSettings
->getNodeType())) {
return;
}
$enabled = $this->nodeSettings
->getEnabled();
if (empty($enabled) || $enabled == 'disabled') {
return;
}
if (array_key_exists($this->nodeId, $results) && !empty($results[$this->nodeId])) {
$severitys = QuailApiSettings::get_severity();
$methods = QuailApiSettings::get_validation_methods();
$result = reset($results[$this->nodeId]);
unset($results);
if (empty($result['report'])) {
unset($result);
$markup = $this
->t('No accessibility violations have been detected.');
}
else {
$reports = $result['report'];
$total = $result['total'];
unset($result);
$format_results = $this->nodeSettings
->getFormatResults();
if (empty($format_results)) {
$format_results = \Drupal::config('quail_api.settings')
->get('filter_format');
}
$title_block = $this->nodeSettings
->getFormatResults();
if (empty($title_block)) {
$title_block = \Drupal::config('quail_api.settings')
->get('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);
}
}
$form_state
->set('fieldset_results][value_results', $markup);
}
$form_state
->setRebuild(TRUE);
$form_state
->setSubmitted(TRUE);
$form_state
->setExecuted(TRUE);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
ValidateFormBase:: |
protected | property | The entity type manager. | |
ValidateFormBase:: |
protected | property | The node ID. | |
ValidateFormBase:: |
protected | property | The node revision ID. | |
ValidateFormBase:: |
protected | property | The node validation settings. | |
ValidateFormBase:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ValidateFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ValidateFormBase:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ValidateFormBase:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ValidateFormBase:: |
public | function | Class Constructor. | |
ValidateFormBase:: |
public | function | Class Destructor. |