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..1b2c20d 100644 --- a/bluecadet_accessibility.module +++ b/bluecadet_accessibility.module @@ -7,21 +7,12 @@ 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) { - // 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'); @@ -34,9 +25,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..5432bdb 100644 --- a/src/EventSubscriber/ViewsAjaxResponseSubscriber.php +++ b/src/EventSubscriber/ViewsAjaxResponseSubscriber.php @@ -2,9 +2,9 @@ namespace Drupal\bluecadet_accessibility\EventSubscriber; -use Drupal\bluecadet_accessibility\Ajax\ViewsAjaxReFocusCommand; 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; @@ -15,6 +15,8 @@ */ class ViewsAjaxResponseSubscriber implements EventSubscriberInterface { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -41,8 +43,14 @@ 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)) { - // Disable the default behavior of visually scrolling on view refreshes caused by form changes or pagination. + 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') { unset($command['command']); @@ -52,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. 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. 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);