From 1f491d7546acbaf7111cad0cefec87158202fe99 Mon Sep 17 00:00:00 2001 From: Brian Canini <canini.16@osu.edu> Date: Tue, 30 Jun 2020 11:00:25 -0400 Subject: [PATCH] Updating drupal/views_ajax_history (1.2.0 => 1.5.0) --- composer.json | 2 +- composer.lock | 21 +++--- vendor/composer/installed.json | 21 +++--- .../schema/views_ajax_history.schema.yml | 6 ++ .../js/views_ajax_history.js | 3 +- .../views/display_extender/AjaxHistory.php | 61 ++++++++++++++++++ .../views_ajax_history.info.yml | 11 ++-- .../views_ajax_history.install | 64 +++++++++++++++++++ .../views_ajax_history.module | 27 +++++++- 9 files changed, 182 insertions(+), 34 deletions(-) create mode 100644 web/modules/views_ajax_history/config/schema/views_ajax_history.schema.yml create mode 100644 web/modules/views_ajax_history/src/Plugin/views/display_extender/AjaxHistory.php create mode 100644 web/modules/views_ajax_history/views_ajax_history.install diff --git a/composer.json b/composer.json index 8e3a9bce10..9dfcd2fbfe 100644 --- a/composer.json +++ b/composer.json @@ -175,7 +175,7 @@ "drupal/video_embed_field": "2.4", "drupal/view_unpublished": "1.0-rc1", "drupal/views_accordion": "1.1", - "drupal/views_ajax_history": "1.2", + "drupal/views_ajax_history": "1.5", "drupal/views_autocomplete_filters": "1.3", "drupal/views_bootstrap": "3.1", "drupal/views_bulk_operations": "3.4", diff --git a/composer.lock b/composer.lock index b3eee3a985..12384d3ceb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "97a7b4312e4113ee81b8d863f237ad12", + "content-hash": "1e41598277bbad67d5818b7d631a5126", "packages": [ { "name": "alchemy/zippy", @@ -8038,29 +8038,26 @@ }, { "name": "drupal/views_ajax_history", - "version": "1.2.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/views_ajax_history.git", - "reference": "8.x-1.2" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_ajax_history-8.x-1.2.zip", - "reference": "8.x-1.2", - "shasum": "97c19dd21327025a58deec6200e008b3c794b022" + "url": "https://ftp.drupal.org/files/projects/views_ajax_history-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "a5c83b97c97b04454b88d34ba96800cfafb779eb" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.2", - "datestamp": "1562339886", + "version": "8.x-1.5", + "datestamp": "1588147485", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index d01d34d36b..dbc70558ea 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -8288,30 +8288,27 @@ }, { "name": "drupal/views_ajax_history", - "version": "1.2.0", - "version_normalized": "1.2.0.0", + "version": "1.5.0", + "version_normalized": "1.5.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/views_ajax_history.git", - "reference": "8.x-1.2" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_ajax_history-8.x-1.2.zip", - "reference": "8.x-1.2", - "shasum": "97c19dd21327025a58deec6200e008b3c794b022" + "url": "https://ftp.drupal.org/files/projects/views_ajax_history-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "a5c83b97c97b04454b88d34ba96800cfafb779eb" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, "drupal": { - "version": "8.x-1.2", - "datestamp": "1562339886", + "version": "8.x-1.5", + "datestamp": "1588147485", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/web/modules/views_ajax_history/config/schema/views_ajax_history.schema.yml b/web/modules/views_ajax_history/config/schema/views_ajax_history.schema.yml new file mode 100644 index 0000000000..978c9b4f14 --- /dev/null +++ b/web/modules/views_ajax_history/config/schema/views_ajax_history.schema.yml @@ -0,0 +1,6 @@ +views.display_extender.ajax_history: + type: views_display_extender + mapping: + enable_history: + type: boolean + label: 'Enable history' diff --git a/web/modules/views_ajax_history/js/views_ajax_history.js b/web/modules/views_ajax_history/js/views_ajax_history.js index a5058acde6..d9e4e22b87 100644 --- a/web/modules/views_ajax_history/js/views_ajax_history.js +++ b/web/modules/views_ajax_history/js/views_ajax_history.js @@ -295,7 +295,8 @@ if (data.view_name && options.type !== 'GET') { // Override the URL to not contain any fields that were submitted. - options.url = drupalSettings.views.ajax_path + '?' + Drupal.ajax.WRAPPER_FORMAT + '=drupal_ajax'; + var delimiter = drupalSettings.views.ajax_path.indexOf('?') === -1 ? '?' : '&'; + options.url = drupalSettings.views.ajax_path + delimiter + Drupal.ajax.WRAPPER_FORMAT + '=drupal_ajax'; } // Call the original Drupal method with the right context. beforeSend.apply(this, arguments); diff --git a/web/modules/views_ajax_history/src/Plugin/views/display_extender/AjaxHistory.php b/web/modules/views_ajax_history/src/Plugin/views/display_extender/AjaxHistory.php new file mode 100644 index 0000000000..62002a9f42 --- /dev/null +++ b/web/modules/views_ajax_history/src/Plugin/views/display_extender/AjaxHistory.php @@ -0,0 +1,61 @@ +<?php + +namespace Drupal\views_ajax_history\Plugin\views\display_extender; + +use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase; +use Drupal\Core\Form\FormStateInterface; + +/** + * Ajax history display extender plugin. + * + * @ingroup views_display_extender_plugins + * + * @ViewsDisplayExtender( + * id = "ajax_history", + * title = @Translation("AJAX history"), + * help = @Translation("Enable the AJAX history feature for the current view."), + * no_ui = FALSE, + * ) + */ +class AjaxHistory extends DisplayExtenderPluginBase { + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + if ($form_state->get('section') == 'use_ajax') { + // Add opportunity to enable view ajax history handler for this view. + $form['enable_history'] = [ + '#title' => $this->t('AJAX history'), + '#type' => 'checkbox', + '#description' => $this->t('Enable Views AJAX history.'), + '#default_value' => isset($this->options['enable_history']) ? $this->options['enable_history'] : 0, + '#states' => [ + 'visible' => [ + ':input[name="use_ajax"]' => ['checked' => TRUE], + ], + ], + ]; + } + } + + /** + * {@inheritdoc} + */ + public function validateOptionsForm(&$form, FormStateInterface $form_state) { + if ($form_state->hasValue('use_ajax') && $form_state->getValue('use_ajax') != TRUE) { + // Prevent use ajax history when ajax for view are disabled. + $form_state->setValue('enable_history', FALSE); + } + } + + /** + * {@inheritdoc} + */ + public function submitOptionsForm(&$form, FormStateInterface $form_state) { + if ($form_state->get('section') == 'use_ajax') { + $this->options['enable_history'] = $form_state->getValue('enable_history'); + } + } + +} diff --git a/web/modules/views_ajax_history/views_ajax_history.info.yml b/web/modules/views_ajax_history/views_ajax_history.info.yml index 5595d6d6bb..05af105db3 100644 --- a/web/modules/views_ajax_history/views_ajax_history.info.yml +++ b/web/modules/views_ajax_history/views_ajax_history.info.yml @@ -1,13 +1,12 @@ -type: module name: 'Views AJAX History' +type: module description: 'Add bookmarking abilities to AJAX Views.' -# core: 8.x +core_version_requirement: ^8.8 || ^9 package: Views dependencies: - drupal:views -# Information added by Drupal.org packaging script on 2019-07-05 -version: '8.x-1.2' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-04-29 +version: '8.x-1.5' project: 'views_ajax_history' -datestamp: 1562339889 +datestamp: 1588147487 diff --git a/web/modules/views_ajax_history/views_ajax_history.install b/web/modules/views_ajax_history/views_ajax_history.install new file mode 100644 index 0000000000..0ab5f592cf --- /dev/null +++ b/web/modules/views_ajax_history/views_ajax_history.install @@ -0,0 +1,64 @@ +<?php + +/** + * Implements hook_install(). + */ +function views_ajax_history_install() { + views_ajax_history_update_views_settings_handler(); +} + +/** + * Enable the ajax_history views display extender. + */ +function views_ajax_history_update_8001() { + views_ajax_history_update_views_settings_handler(); + + // Keep the previous behavior of the module by enabling the new 'ajax_history' + // display extender on every view that uses AJAX. + $config_factory = \Drupal::configFactory(); + foreach ($config_factory->listAll('views.view.') as $view_config_name) { + $config = $config_factory->getEditable($view_config_name); + if (!$config->get('display')['default']['display_options']['use_ajax'] == TRUE) { + continue; + } + + $save = FALSE; + foreach ($config->get('display') as $display_id => $display) { + if (!isset($display['display_options']['display_extenders']['ajax_history'])) { + $display['display_options']['display_extenders']['ajax_history']['enable_history'] = TRUE; + $config->set("display.$display_id", $display); + $save = TRUE; + } + } + if ($save) { + $config->save(TRUE); + } + } +} + +/** + * Helper function for enable display extender for Views. + */ +function views_ajax_history_update_views_settings_handler() { + // Enable ajax_history plugin. + $config = \Drupal::service('config.factory')->getEditable('views.settings'); + $display_extenders = $config->get('display_extenders') ?: []; + $display_extenders[] = 'ajax_history'; + $config->set('display_extenders', $display_extenders); + $config->save(); +} + +/** + * Implements hook_uninstall(). + */ +function views_ajax_history_uninstall() { + // Disable ajax_history plugin. + $config = \Drupal::service('config.factory')->getEditable('views.settings'); + $display_extenders = $config->get('display_extenders') ?: []; + $key = array_search('ajax_history', $display_extenders); + if ($key !== FALSE) { + unset($display_extenders[$key]); + $config->set('display_extenders', $display_extenders); + $config->save(); + } +} diff --git a/web/modules/views_ajax_history/views_ajax_history.module b/web/modules/views_ajax_history/views_ajax_history.module index d335bdaea6..fe8fecb09a 100644 --- a/web/modules/views_ajax_history/views_ajax_history.module +++ b/web/modules/views_ajax_history/views_ajax_history.module @@ -6,15 +6,38 @@ */ use \Drupal\views\ViewExecutable; +use Drupal\Core\Routing\RouteMatchInterface; + +/** + * Implements hook_help(). + */ +function views_ajax_history_help($route_name, RouteMatchInterface $arg) { + switch ($route_name) { + case 'help.page.views_ajax_history': + $output = ''; + $output .= '<h3>' . t('About') . '</h3>'; + $output .= '<p>' . t('Enable bookmaking of AJAX views. Supports filters and paging.') . '</p>'; + + // Add a link to the Drupal.org project. + $output .= '<p>'; + $output .= t('Visit the <a href=":project_link">Views AJAX History project pages</a> on Drupal.org for more information.',[ + ':project_link' => 'https://www.drupal.org/project/views_ajax_history' + ]); + $output .= '</p>'; + + return $output; + } +} /** * Implements hook_views_pre_render(). */ function views_ajax_history_views_pre_render(ViewExecutable $view) { - if ($view->ajaxEnabled() && empty($view->is_attachment) && empty($view->live_preview)) { + $display_extenders_options = $view->display_handler->getOption('display_extenders'); + if (($view->ajaxEnabled() && (isset($display_extenders_options['ajax_history']['enable_history']) && $display_extenders_options['ajax_history']['enable_history'] == TRUE)) && empty($view->is_attachment) && empty($view->live_preview)) { // @TODO add option to views form for html4+html5 or html5 only $view->element['#attached']['library'][] = 'views_ajax_history/history'; - $view->element['#attached']['drupalSettings']['viewsAjaxHistory'] = ['renderPageItem' => pager_find_page()]; + $view->element['#attached']['drupalSettings']['viewsAjaxHistory'] = ['renderPageItem' => \Drupal::service('pager.parameters')->findPage()]; $view->element['#cache']['contexts'][] = 'url.query_args.pagers'; } } -- GitLab