From 77eae6069fde55b108fc93f2d23e3be8d0a93c89 Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 14:57:05 -0500 Subject: [PATCH 1/9] phpcs fixes --- bluecadet_accessibility.install | 11 ++++++--- bluecadet_accessibility.module | 16 ++++--------- .../ViewsAjaxResponseSubscriber.php | 23 +++++++++++-------- .../views/display_extender/AjaxAllyOption.php | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/bluecadet_accessibility.install b/bluecadet_accessibility.install index 9de9bf8..c7fae49 100644 --- a/bluecadet_accessibility.install +++ b/bluecadet_accessibility.install @@ -1,5 +1,10 @@ getEditable('views.settings'); - $display_extenders = $config->get('display_extenders') ?: array(); + $display_extenders = $config->get('display_extenders') ?: []; $display_extenders[] = 'ajax_ally_option'; $config->set('display_extenders', $display_extenders); $config->save(); @@ -25,10 +30,10 @@ function bluecadet_accessibility_enable_plugin() { function bluecadet_accessibility_uninstall() { // Disable ajax_ally_option plugin. $config = \Drupal::service('config.factory')->getEditable('views.settings'); - $display_extenders = $config->get('display_extenders') ?: array(); + $display_extenders = $config->get('display_extenders') ?: []; $key = array_search('ajax_ally_option', $display_extenders); - if ($key!== FALSE) { + if ($key !== FALSE) { unset($display_extenders[$key]); $config->set('display_extenders', $display_extenders); $config->save(); diff --git a/bluecadet_accessibility.module b/bluecadet_accessibility.module index 51b519d..7a2313c 100644 --- a/bluecadet_accessibility.module +++ b/bluecadet_accessibility.module @@ -7,19 +7,13 @@ use Drupal\views\ViewExecutable; -/** - * Implements hook_page_attachments(). - */ -// function bluecadet_accessibility_page_attachments(array &$attachments) { -// $attachments['#attached']['library'][] = 'bluecadet_accessibility/bluecadet_accessibility'; -// } - /** * Implements hook_form_views_pre_render(). * * Add instance dates to view results. */ -function bluecadet_accessibility_views_pre_render(ViewExecutable $view) { +function bluecadet_accessibility_views_pre_render(ViewExecutable $view) +{ // Grab the current view display. $display = $view->getDisplay(); @@ -34,9 +28,9 @@ function bluecadet_accessibility_views_pre_render(ViewExecutable $view) { ) ) && empty($view->is_attachment) && empty($view->live_preview) - ) { + ) { - // Attach the library. - $view->element['#attached']['library'][] = 'bluecadet_accessibility/viewsAjaxA11y'; + // Attach the library. + $view->element['#attached']['library'][] = 'bluecadet_accessibility/viewsAjaxA11y'; } } diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index ce37003..a141b6d 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -2,7 +2,6 @@ namespace Drupal\bluecadet_accessibility\EventSubscriber; -use Drupal\bluecadet_accessibility\Ajax\ViewsAjaxReFocusCommand; use Drupal\Core\Ajax\AnnounceCommand; use Drupal\Core\Ajax\FocusFirstCommand; use Drupal\views\Ajax\ViewAjaxResponse; @@ -13,12 +12,14 @@ /** * Alter a Views Ajax Response. */ -class ViewsAjaxResponseSubscriber implements EventSubscriberInterface { +class ViewsAjaxResponseSubscriber implements EventSubscriberInterface +{ /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents() + { $events[KernelEvents::RESPONSE][] = ['onResponse']; return $events; } @@ -29,7 +30,8 @@ public static function getSubscribedEvents() { * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event * The event process. */ - public function onResponse(FilterResponseEvent $event) { + public function onResponse(FilterResponseEvent $event) + { $response = $event->getResponse(); // Only act on a Views Ajax Response. @@ -41,7 +43,12 @@ public function onResponse(FilterResponseEvent $event) { $display_extenders_options = $view->display_handler->getOption('display_extenders'); - if (($view->ajaxEnabled() && (isset($display_extenders_options['ajax_ally_option']['enable_ally']) && $display_extenders_options['ajax_ally_option']['enable_ally'] == TRUE)) && empty($view->is_attachment) && empty($view->live_preview)) { + if ( + ($view->ajaxEnabled() && (isset($display_extenders_options['ajax_ally_option']['enable_ally']) + && $display_extenders_options['ajax_ally_option']['enable_ally'] == TRUE) + ) + && empty($view->is_attachment) && empty($view->live_preview) + ) { // Disable the default behavior of visually scrolling on view refreshes caused by form changes or pagination. foreach ($commands as &$command) { if (isset($command['command']) && $command['command'] === 'viewsScrollTop') { @@ -52,20 +59,18 @@ public function onResponse(FilterResponseEvent $event) { // Add in Announce for number of results. $result_count = count($view->result); // @todo variablise this in a settings page. - $msg = \Drupal::translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.');; + $msg = \Drupal::translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); $response->addCommand(new AnnounceCommand($msg, 'assertive')); // Add in focus command. if ($result_count > 0) { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-content ul li')); - } - else { + } else { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-empty [tabindex="0"]')); } } } } - } diff --git a/src/Plugin/views/display_extender/AjaxAllyOption.php b/src/Plugin/views/display_extender/AjaxAllyOption.php index 35d47c5..ab1b265 100644 --- a/src/Plugin/views/display_extender/AjaxAllyOption.php +++ b/src/Plugin/views/display_extender/AjaxAllyOption.php @@ -2,8 +2,8 @@ namespace Drupal\bluecadet_accessibility\Plugin\views\display_extender; -use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase; /** * Ajax AJAX A11y display extender plugin. From da3d6688a1a242a8a9b90075b861311f063c6381 Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 15:05:55 -0500 Subject: [PATCH 2/9] fix opening brace errors --- bluecadet_accessibility.module | 3 +-- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 13 ++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bluecadet_accessibility.module b/bluecadet_accessibility.module index 7a2313c..9e8cb6c 100644 --- a/bluecadet_accessibility.module +++ b/bluecadet_accessibility.module @@ -12,8 +12,7 @@ use Drupal\views\ViewExecutable; * * Add instance dates to view results. */ -function bluecadet_accessibility_views_pre_render(ViewExecutable $view) -{ +function bluecadet_accessibility_views_pre_render(ViewExecutable $view) { // Grab the current view display. $display = $view->getDisplay(); diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index a141b6d..22d8c63 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -12,14 +12,12 @@ /** * Alter a Views Ajax Response. */ -class ViewsAjaxResponseSubscriber implements EventSubscriberInterface -{ +class ViewsAjaxResponseSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ - public static function getSubscribedEvents() - { + public static function getSubscribedEvents() { $events[KernelEvents::RESPONSE][] = ['onResponse']; return $events; } @@ -30,8 +28,7 @@ public static function getSubscribedEvents() * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event * The event process. */ - public function onResponse(FilterResponseEvent $event) - { + public function onResponse(FilterResponseEvent $event) { $response = $event->getResponse(); // Only act on a Views Ajax Response. @@ -66,11 +63,13 @@ public function onResponse(FilterResponseEvent $event) if ($result_count > 0) { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-content ul li')); - } else { + } + else { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-empty [tabindex="0"]')); } } } } + } From 4eb2e90415ff206d76f0cdc5762919b7dca9871c Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 15:13:54 -0500 Subject: [PATCH 3/9] fix white space and extra long comment --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 22d8c63..5629a23 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -46,7 +46,8 @@ public function onResponse(FilterResponseEvent $event) { ) && empty($view->is_attachment) && empty($view->live_preview) ) { - // Disable the default behavior of visually scrolling on view refreshes caused by form changes or pagination. + // Disable the default behavior of visually scrolling + // on view refreshes caused by form changes or pagination. foreach ($commands as &$command) { if (isset($command['command']) && $command['command'] === 'viewsScrollTop') { unset($command['command']); @@ -63,7 +64,7 @@ public function onResponse(FilterResponseEvent $event) { if ($result_count > 0) { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-content ul li')); - } + } else { // @todo variablise this in a settings page. $response->addCommand(new FocusFirstCommand($view_selector . ' .view-empty [tabindex="0"]')); From c57365962fec360fa86dddc9a7980704aadd174b Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 15:20:04 -0500 Subject: [PATCH 4/9] fix whitespace issue --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 5629a23..8389704 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -46,7 +46,7 @@ public function onResponse(FilterResponseEvent $event) { ) && empty($view->is_attachment) && empty($view->live_preview) ) { - // Disable the default behavior of visually scrolling + // Disable the default behavior of visually scrolling // on view refreshes caused by form changes or pagination. foreach ($commands as &$command) { if (isset($command['command']) && $command['command'] === 'viewsScrollTop') { From df0f0e43c299ef342a7556fbb3e32c3b06c335d6 Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 15:31:34 -0500 Subject: [PATCH 5/9] remove unused vars --- bluecadet_accessibility.module | 2 -- tests/src/Functional/BluecadeAccessibilityTest.php | 1 - 2 files changed, 3 deletions(-) diff --git a/bluecadet_accessibility.module b/bluecadet_accessibility.module index 9e8cb6c..1b2c20d 100644 --- a/bluecadet_accessibility.module +++ b/bluecadet_accessibility.module @@ -13,8 +13,6 @@ use Drupal\views\ViewExecutable; * Add instance dates to view results. */ function bluecadet_accessibility_views_pre_render(ViewExecutable $view) { - // Grab the current view display. - $display = $view->getDisplay(); // Grab the options set on the view display. $display_extenders_options = $view->display_handler->getOption('display_extenders'); diff --git a/tests/src/Functional/BluecadeAccessibilityTest.php b/tests/src/Functional/BluecadeAccessibilityTest.php index 2447173..93c79ab 100644 --- a/tests/src/Functional/BluecadeAccessibilityTest.php +++ b/tests/src/Functional/BluecadeAccessibilityTest.php @@ -69,7 +69,6 @@ protected function setUp() : void { * Test Basic Functionality. */ public function testBasicFunc() { - $session = $this->assertSession(); $this->assertTrue(TRUE); From 8c7e8baab0e547b16a65d42bfb4f6d5cd8f13d49 Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 16:10:16 -0500 Subject: [PATCH 6/9] use statement for translation manager --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 8389704..1f21bb3 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -4,6 +4,7 @@ use Drupal\Core\Ajax\AnnounceCommand; use Drupal\Core\Ajax\FocusFirstCommand; +use Drupal\Core\StringTranslation\TranslationManager; use Drupal\views\Ajax\ViewAjaxResponse; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -57,7 +58,7 @@ public function onResponse(FilterResponseEvent $event) { // Add in Announce for number of results. $result_count = count($view->result); // @todo variablise this in a settings page. - $msg = \Drupal::translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); + $msg = new translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); $response->addCommand(new AnnounceCommand($msg, 'assertive')); // Add in focus command. From 02ddc0a32bce6651f77afb62af8cbe29ffe09b4c Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Tue, 30 Jan 2024 16:13:37 -0500 Subject: [PATCH 7/9] revert translation use --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 1f21bb3..8389704 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -4,7 +4,6 @@ use Drupal\Core\Ajax\AnnounceCommand; use Drupal\Core\Ajax\FocusFirstCommand; -use Drupal\Core\StringTranslation\TranslationManager; use Drupal\views\Ajax\ViewAjaxResponse; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -58,7 +57,7 @@ public function onResponse(FilterResponseEvent $event) { // Add in Announce for number of results. $result_count = count($view->result); // @todo variablise this in a settings page. - $msg = new translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); + $msg = \Drupal::translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); $response->addCommand(new AnnounceCommand($msg, 'assertive')); // Add in focus command. From 4a128736f86511b26d5582334f3b9ac4625955a2 Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Wed, 31 Jan 2024 15:51:58 -0500 Subject: [PATCH 8/9] use use statement for stringTranslationTrait --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 8389704..0eccc55 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -4,6 +4,7 @@ use Drupal\Core\Ajax\AnnounceCommand; use Drupal\Core\Ajax\FocusFirstCommand; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\Ajax\ViewAjaxResponse; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -13,6 +14,8 @@ * Alter a Views Ajax Response. */ class ViewsAjaxResponseSubscriber implements EventSubscriberInterface { + + use StringTranslationTrait; /** * {@inheritdoc} @@ -57,7 +60,7 @@ public function onResponse(FilterResponseEvent $event) { // Add in Announce for number of results. $result_count = count($view->result); // @todo variablise this in a settings page. - $msg = \Drupal::translation()->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); + $msg = $this->formatPlural($result_count, '1 result loaded.', '@count results loaded.'); $response->addCommand(new AnnounceCommand($msg, 'assertive')); // Add in focus command. From d76b64fbb9054d25ef481e4b2f855e93973e37ad Mon Sep 17 00:00:00 2001 From: Amy Frear Date: Wed, 31 Jan 2024 15:55:49 -0500 Subject: [PATCH 9/9] delete white space --- src/EventSubscriber/ViewsAjaxResponseSubscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php index 0eccc55..5432bdb 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -14,7 +14,7 @@ * Alter a Views Ajax Response. */ class ViewsAjaxResponseSubscriber implements EventSubscriberInterface { - + use StringTranslationTrait; /**