diff --git a/composer.json b/composer.json index 2ce06e518233c8b8451b383ff8be7150ff880a3c..854634255b5fca7eacb4381123a63688d121a875 100644 --- a/composer.json +++ b/composer.json @@ -133,7 +133,7 @@ "drupal/token": "1.0", "drupal/userprotect": "1.0", "drupal/video_embed_field": "2.0", - "drupal/views_accordion": "1.0-beta2", + "drupal/views_accordion": "1.1", "drupal/views_ajax_history": "^1.0", "drupal/views_autocomplete_filters": "1.1", "drupal/views_bootstrap": "3.x-dev", diff --git a/composer.lock b/composer.lock index 4af46487dd3f45f9fde7da0714001c442a3505ef..80529fac6daa75520e376d4843de547fb10d941f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2df083d770e28fc281b43122b934f357", + "content-hash": "5e82b716556fb4aa7de504a393508053", "packages": [ { "name": "alchemy/zippy", @@ -5621,17 +5621,17 @@ }, { "name": "drupal/views_accordion", - "version": "1.0.0-beta2", + "version": "1.1.0", "source": { "type": "git", "url": "https://git.drupal.org/project/views_accordion", - "reference": "8.x-1.0-beta2" + "reference": "8.x-1.1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_accordion-8.x-1.0-beta2.zip", - "reference": "8.x-1.0-beta2", - "shasum": "943ab7b2d530e3885fcaf5cc30817e956c6759ef" + "url": "https://ftp.drupal.org/files/projects/views_accordion-8.x-1.1.zip", + "reference": "8.x-1.1", + "shasum": "2e5e1f758141bf271b26f1e4631211dfaa5dae27" }, "require": { "drupal/core": "*" @@ -5642,11 +5642,11 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.0-beta2", - "datestamp": "1494784384", + "version": "8.x-1.1", + "datestamp": "1521988085", "security-coverage": { - "status": "not-covered", - "message": "Beta releases are not covered by Drupal security advisories." + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 6e55505abf004bbfabc2897cb6a6e4a50ea4f948..b55a68d136718f98f804ada62f34221e51cac446 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -5797,18 +5797,18 @@ }, { "name": "drupal/views_accordion", - "version": "1.0.0-beta2", - "version_normalized": "1.0.0.0-beta2", + "version": "1.1.0", + "version_normalized": "1.1.0.0", "source": { "type": "git", "url": "https://git.drupal.org/project/views_accordion", - "reference": "8.x-1.0-beta2" + "reference": "8.x-1.1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/views_accordion-8.x-1.0-beta2.zip", - "reference": "8.x-1.0-beta2", - "shasum": "943ab7b2d530e3885fcaf5cc30817e956c6759ef" + "url": "https://ftp.drupal.org/files/projects/views_accordion-8.x-1.1.zip", + "reference": "8.x-1.1", + "shasum": "2e5e1f758141bf271b26f1e4631211dfaa5dae27" }, "require": { "drupal/core": "*" @@ -5819,11 +5819,11 @@ "dev-1.x": "1.x-dev" }, "drupal": { - "version": "8.x-1.0-beta2", - "datestamp": "1494784384", + "version": "8.x-1.1", + "datestamp": "1521988085", "security-coverage": { - "status": "not-covered", - "message": "Beta releases are not covered by Drupal security advisories." + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, diff --git a/web/modules/views_accordion/README.txt b/web/modules/views_accordion/README.txt index 4d4d6ab85c2cb2701800dc232467ac0ad5f9ab92..d14b91d48deadf24bb1f751fa1419789b833e68f 100644 --- a/web/modules/views_accordion/README.txt +++ b/web/modules/views_accordion/README.txt @@ -2,26 +2,30 @@ /* DESCRIPTION */ Views Accordion provides a display style plugin for the Views module. -It will take the results and display them as a JQuery accordion. It supports grouping of fields and ajax pagination. +It will take the results and display them as a JQuery accordion. It supports +grouping of fields and ajax pagination. /* INSTALATION */ -1. Place the views_accordion module in your modules directory (usually under /modules/). +1. Place the views_accordion module in your modules directory (usually under + /modules/). 2. Go to /admin/modules, and activate the module. /* USING VIEWS ACCORDION MODULE */ Your view must meet the following requirements: - * Row style must be set to Fields + * Row style must be set to Fields. * Provide at least two fields to show. -Choose Views Accordion in the Style dialog within your view, which will prompt you to configure the jquery.ui.accorion settings. +Choose jQuery UI accordion in the Style dialog within your view, which will prompt +you to configure the jquery.ui.accorion settings. -* IMPORTANT * -The first field WILL be used as the header for each accordion section, all others will be displayed -when the header is clicked. The module creates an accordion section per row of results from the view. +* IMPORTANT * +The first field WILL be used as the header for each accordion section, all +others will be displayed when the header is clicked. The module creates an +accordion section per row of results from the view. ************************** diff --git a/web/modules/views_accordion/config/schema/views.style.views_accordion.schema.yml b/web/modules/views_accordion/config/schema/views.style.views_accordion.schema.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3388a6422c9319f57ff9fbc098f4832abffd371 --- /dev/null +++ b/web/modules/views_accordion/config/schema/views.style.views_accordion.schema.yml @@ -0,0 +1,36 @@ +views.style.views_accordion: + type: views_style + label: 'Views Accordion' + mapping: + disableifone: + type: integer + label: 'Disable if only one result' + row-start-open: + type: string + label: 'Row to display opened on start' + collapsible: + type: integer + label: 'Collapsible' + animated: + type: string + label: 'Animation effect' + animation_time: + type: string + label: 'Animation time' + heightStyle: + type: string + label: 'heightStyle' + event: + type: string + label: 'Event' + use_header_icons: + type: integer + label: 'Use header icons' + icon_header: + type: 'string' + label: 'Closed row header icon' + icon_active_header: + type: 'string' + label: 'Opened row header icon' + + diff --git a/web/modules/views_accordion/src/Plugin/views/style/ViewsAccordion.php b/web/modules/views_accordion/src/Plugin/views/style/ViewsAccordion.php index 2d13016e20881a0f3752b0ff4f5378cd27a8839c..2b271ed8b57c837f68d353827bcc0dfb417e5d78 100644 --- a/web/modules/views_accordion/src/Plugin/views/style/ViewsAccordion.php +++ b/web/modules/views_accordion/src/Plugin/views/style/ViewsAccordion.php @@ -20,22 +20,17 @@ */ class ViewsAccordion extends StylePluginBase { /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::usesRowPlugin + * {@inheritdoc} */ protected $usesRowPlugin = TRUE; /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::usesRowClass. - */ + * {@inheritdoc} + */ protected $usesRowClass = TRUE; /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::groupingTheme. - */ - // protected $groupingTheme = 'views_view_grouping'; - - /** - * Set default options + * Set default options. */ protected function defineOptions() { $options = parent::defineOptions(); @@ -59,17 +54,17 @@ protected function defineOptions() { public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); - //// available valid options for grouping (used for use-grouping-header #dependency) - foreach ($this->displayHandler->getHandlers('field') as $field => $handler) { - $options[] = $field; - } - // Find out how many items the display is currently configured to show (row-start-open) + // Find out how many items the display is currently configured to show + // (row-start-open). $maxitems = $this->displayHandler->getOption('items_per_page'); - $maxitems = ($maxitems == 0) ? 10 : $maxitems; // if items_per_page is set to unlimitted (0), 10 rows will be what the user gets to choose from. + // If items_per_page is set to unlimitted (0), 10 rows will be what the user + // gets to choose from. + $maxitems = ($maxitems == 0) ? 10 : $maxitems; - // Setup our array of options for choosing which row should start opened (row-start-open) + // Setup our array of options for choosing which row should start opened + // (row-start-open). $rsopen_options = []; - for ($i = 1; $i <= $maxitems; $i++){ + for ($i = 1; $i <= $maxitems; $i++) { $rsopen_options[] = $this->t('Row @number', ['@number' => $i]); } $rsopen_options['none'] = $this->t('None'); @@ -124,7 +119,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('Use the group header as the Accordion header'), '#default_value' => $grouping['use-grouping-header'], - '#description' => $this->t('If checked, the Group\'s header will be used to open/close the accordion.'), + '#description' => $this->t("If checked, the Group's header will be used to open/close the accordion."), '#states' => [ 'invisible' => [ ':input[name="style_options[grouping][' . $i . '][field]"]' => ['value' => ''], @@ -132,7 +127,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ], ]; } - $form['grouping']['#prefix'] = '<div class="form-item">'. $this->t('<strong>IMPORTANT:</strong> The <em>first field</em> in order of appearance <em>will</em> be the one used as the "header" or "trigger" of the accordion action.') .'</div>'; + $form['grouping']['#prefix'] = '<div class="form-item">' . $this->t('<strong>IMPORTANT:</strong> The <em>first field</em> in order of appearance <em>will</em> be the one used as the "header" or "trigger" of the accordion action.') . '</div>'; $form['disableifone'] = [ '#type' => 'checkbox', @@ -169,16 +164,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#step' => 1, '#description' => $this->t('The animation duration in milliseconds'), ]; - $form['heightStyle'] = [ + $form['heightStyle'] = [ '#type' => 'select', '#title' => $this->t('heightStyle'), '#default_value' => $this->options['heightStyle'], '#description' => $this->t('Controls the height of the accordion and each panel.'), - '#options' => [ + '#options' => [ 'auto' => 'auto', 'fill' => 'fill', 'content' => 'content', - ] + ], ]; $form['event'] = [ '#type' => 'select', @@ -194,11 +189,11 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('Use header icons'), '#default_value' => $this->options['use_header_icons'], - '#description' => $this->t('Icons to use for headers, matching an icon provided by the <a href="http://api.jqueryui.com/theming/icons/" target="_false">jQuery UI CSS Framework</a>. Uncheck to have no icons displayed.') + '#description' => $this->t('Icons to use for headers, matching an icon provided by the <a href="http://api.jqueryui.com/theming/icons/" target="_false">jQuery UI CSS Framework</a>. Uncheck to have no icons displayed.'), ]; $show_if_use_header_icons = [ 'visible' => [ - ':input[name="style_options[use_header_icons]"]' => array('checked' => TRUE), + ':input[name="style_options[use_header_icons]"]' => ['checked' => TRUE], ], ]; $form['icon_header'] = [ @@ -215,40 +210,49 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ]; } + /** + * {@inheritdoc} + */ public function preRender($result) { - // no need do anything if we we have only one result and disableifone is active + // No need do anything if we we have only one result and disableifone is + // active. if ($this->options['disableifone'] == '1') { - if(count($result) < 2) { + if (count($result) < 2) { return; } } $view_settings = []; $header_class = 'views-accordion-header'; + // This is used for triggering the creation of the accordions. + // We append the dom_id so that multiple nested views with accordions work. + $accordion_header_class = 'js-' . $header_class . '-' . $this->view->dom_id; $view_settings['usegroupheader'] = FALSE; foreach ($this->options['grouping'] as $group) { - $view_settings['usegroupheader'] = $group['use-grouping-header'] == 1; - break; // @TODO handle multiple grouping + $view_settings['usegroupheader'] = $group['use-grouping-header'] == 1; + // @TODO handle multiple grouping. + break; } - // Find out about the header field options + // Find out about the header field options. $fields = array_values($this->displayHandler->getOption('fields')); - // Add header class to first not-excluded field + // Add header class to first not-excluded field. foreach ($fields as $field) { if (!isset($field['exclude']) || ($field['exclude'] == 0)) { - // make sure we are using a div for markup at least + // Make sure we are using a div for markup at least. if (empty($field['element_wrapper_type'])) { - $this->view->field[$field['id']]->options['element_wrapper_type'] = 'div'; + $this->view->field[$field['id']]->options['element_wrapper_type'] = 'div'; } - // Setup our wrapper class if not using group header + // Setup our wrapper class if not using group header. if (!$view_settings['usegroupheader']) { - $header_wrapper_class = $header_class; - // if the user configured its own class, set that up with our own class - if(!empty($field['element_wrapper_class'])) { - $header_wrapper_class = $field['element_wrapper_class'] .' '. $header_class; + $header_wrapper_class = $header_class . ' ' . $accordion_header_class; + // If the user configured its own class, set that up with our own + // class. + if (!empty($field['element_wrapper_class'])) { + $header_wrapper_class = $field['element_wrapper_class'] . ' ' . $header_wrapper_class; } - // setup the view to use our processed wrapper class + // Setup the view to use our processed wrapper class. $this->view->field[$field['id']]->options['element_wrapper_class'] = $header_wrapper_class; } break; @@ -257,23 +261,16 @@ public function preRender($result) { $this->view->element['#attached']['library'][] = 'views_accordion/views_accordion.accordion'; - // Add the appropiate effect library if necessary + // Add the appropiate effect library if necessary. $effect = $this->options['animated']; - if(($effect !== 'none') && ($effect !== 'swing') && ($effect !== 'linear')){ - // For now we only use ui core effects library, which provides the easing effects. - // this switch is left here in case we want to integrate and load any other libraries - switch($effect) { - default: - $library = 'core/jquery.ui.effects.core'; - break; - } - if(isset($library)){ - $this->view->element['#attached']['library'][] = $library; - } + if (($effect !== 'none') && ($effect !== 'swing') && ($effect !== 'linear')) { + // jquery.ui.effects.core provides the easing effects. + // It would be possible to integrate and load any other libraries here. + $this->view->element['#attached']['library'][] = 'core/jquery.ui.effects.core'; } // Prepare the JS settings. - // We do it here so we don't have it run once every group + // We do it here so we don't have it run once every group. $view_settings['collapsible'] = $this->options['collapsible']; if ($this->options['row-start-open'] == 'random') { $view_settings['rowstartopen'] = 'random'; @@ -291,10 +288,11 @@ public function preRender($result) { $view_settings['iconActiveHeader'] = $this->options['icon_active_header']; } // The view display selector. - $view_settings['display'] = '.js-view-dom-id-' . $this->view->dom_id; // set in stable & classy themes + // Set in stable & classy themes. + $view_settings['display'] = '.js-view-dom-id-' . $this->view->dom_id; // The accordion header selector. - $view_settings['header'] = '.' . $header_class; + $view_settings['header'] = '.' . $accordion_header_class; if ($view_settings['usegroupheader']) { // @TODO we cannot set a class for the grouping h3 apparently... $view_settings['header'] = '.js-views-accodion-group-header'; @@ -304,7 +302,7 @@ public function preRender($result) { } /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::render(). + * {@inheritdoc} */ public function render() { $rows = parent::render(); @@ -312,13 +310,13 @@ public function render() { '#theme' => $this->themeFunctions(), '#view' => $this->view, '#options' => $this->options, - '#rows' => $rows + '#rows' => $rows, ]; return $output; } /** - * Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::validate(). + * {@inheritdoc} */ public function validate() { $errors = parent::validate(); @@ -326,15 +324,17 @@ public function validate() { $errors[] = $this->t('Views accordion requires Fields as row style'); } - foreach($this->options['grouping'] as $group) { + foreach ($this->options['grouping'] as $group) { if (!$group['rendered'] && $group['use-grouping-header']) { $errors[] = $this->t('Views accordion requires "Use rendered output to group rows" enabled in order to use the group header as the Accordion header.'); } - break; // @TODO handle multiple grouping + // @TODO handle multiple grouping. + break; } - if ($this->options['collapsible'] !== 1 && $this->options['row-start-open'] == 'none') { + if ($this->options['collapsible'] !== 1 && $this->options['row-start-open'] === 'none') { $errors[] = $this->t('Setting "Row to display opened on start" to "None" requires "Collapsible" to be enabled.'); } return $errors; } + } diff --git a/web/modules/views_accordion/tests/modules/views_accordion_test/config/install/views.view.views_accordion_test.yml b/web/modules/views_accordion/tests/modules/views_accordion_test/config/install/views.view.views_accordion_test.yml new file mode 100644 index 0000000000000000000000000000000000000000..6ddf526ce98cdb788fa186e6f5ee23e8e9a303b5 --- /dev/null +++ b/web/modules/views_accordion/tests/modules/views_accordion_test/config/install/views.view.views_accordion_test.yml @@ -0,0 +1,263 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.body + module: + - node + - text + - user + - views_accordion +id: views_accordion_test +label: 'Views Accordion Test' +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'access content' + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: mini + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: ‹‹ + next: ›› + style: + type: views_accordion + options: + grouping: { } + row_class: '' + default_row_class: true + disableifone: 0 + row-start-open: '0' + collapsible: 0 + animated: none + animation_time: '300' + heightStyle: auto + event: click + use_header_icons: 1 + icon_header: ui-icon-triangle-1-e + icon_active_header: ui-icon-triangle-1-s + row: + type: fields + options: + inline: { } + separator: '' + hide_empty: false + default_field_elements: true + fields: + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + label: '' + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + settings: + link_to_entity: true + plugin_id: field + relationship: none + group_type: group + admin_label: '' + exclude: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_alter_empty: true + click_sort_column: value + type: string + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + body: + id: body + table: node__body + field: body + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: text_summary_or_trimmed + settings: + trim_length: 600 + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + plugin_id: field + filters: { } + sorts: { } + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + filter_groups: + operator: AND + groups: { } + title: 'Views Accordion Test' + use_ajax: false + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:field.storage.node.body' + - extensions + block_1: + display_plugin: block + id: block_1 + display_title: Block + position: 2 + display_options: + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:field.storage.node.body' + - extensions + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: 1 + display_options: + display_extenders: { } + path: views-accordion-test + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:field.storage.node.body' + - extensions diff --git a/web/modules/views_accordion/tests/modules/views_accordion_test/views_accordion_test.info.yml b/web/modules/views_accordion/tests/modules/views_accordion_test/views_accordion_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..2e821210760ad3201c02238c0bd5c58f6eea1a4a --- /dev/null +++ b/web/modules/views_accordion/tests/modules/views_accordion_test/views_accordion_test.info.yml @@ -0,0 +1,15 @@ +name: 'Views Accordion Test' +type: module +description: 'Provides test config for views_accordion module tests.' +# core: 8.x +dependencies: + - drupal:node + - drupal:views + - drupal:text + - drupal:views_accordion + +# Information added by Drupal.org packaging script on 2018-03-25 +version: '8.x-1.1' +core: '8.x' +project: 'views_accordion' +datestamp: 1521988091 diff --git a/web/modules/views_accordion/tests/src/Functional/ViewsAccordionTest.php b/web/modules/views_accordion/tests/src/Functional/ViewsAccordionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..626f0b39b5561b5a6f0018e809408472f06a7885 --- /dev/null +++ b/web/modules/views_accordion/tests/src/Functional/ViewsAccordionTest.php @@ -0,0 +1,79 @@ +<?php + +namespace Drupal\Tests\views_accordion\Functional; + +use Drupal\Tests\BrowserTestBase; + +/** + * Functional tests for the Views Accordion module. + * + * @group views_accordion + */ +class ViewsAccordionTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'views_accordion_test', + 'views_ui', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $user = $this->drupalCreateUser([ + 'access administration pages', + 'administer views', + ]); + $this->drupalLogin($user); + } + + /** + * Tests Views Accordion functionality. + */ + public function testViewsAccordion() { + $assert_session = $this->assertSession(); + // Test views add form. + $edit = [ + 'id' => 'test', + 'label' => 'test', + 'show[wizard_key]' => 'node', + 'show[sort]' => 'none', + 'page[create]' => 1, + 'page[title]' => 'Test', + 'page[path]' => 'test', + 'page[style][style_plugin]' => 'views_accordion', + 'page[style][row_plugin]' => 'teasers', + ]; + $this->drupalPostForm('admin/structure/views/add', $edit, 'Save and edit'); + $assert_session->pageTextContains('Views accordion requires Fields as row style'); + + $edit['page[style][row_plugin]'] = 'fields'; + $this->drupalPostForm('admin/structure/views/add', $edit, 'Save and edit'); + $assert_session->pageTextContains('The view test has been saved.'); + + // Assert the options of our exported view display correctly. + $this->drupalGet('admin/structure/views/view/views_accordion_test/edit'); + $assert_session->statusCodeEquals(200); + $assert_session->pageTextContains('jQuery UI accordion'); + + // Verify the style options show with the right values in the form. + $this->drupalGet('admin/structure/views/nojs/display/views_accordion_test/page_1/style_options'); + $assert_session->statusCodeEquals(200); + $assert_session->checkboxNotChecked('style_options[grouping][0][use-grouping-header]'); + $assert_session->checkboxNotChecked('style_options[disableifone]'); + $assert_session->checkboxNotChecked('style_options[collapsible]'); + $assert_session->fieldValueEquals('style_options[animated]', 'none'); + $assert_session->fieldValueEquals('style_options[animation_time]', '300'); + $assert_session->fieldValueEquals('style_options[heightStyle]', 'auto'); + $assert_session->fieldValueEquals('style_options[event]', 'click'); + $assert_session->checkboxChecked('style_options[use_header_icons]'); + $assert_session->fieldValueEquals('style_options[icon_header]', 'ui-icon-triangle-1-e'); + $assert_session->fieldValueEquals('style_options[icon_active_header]', 'ui-icon-triangle-1-s'); + } + +} diff --git a/web/modules/views_accordion/tests/src/FunctionalJavascript/ViewsAccordionTest.php b/web/modules/views_accordion/tests/src/FunctionalJavascript/ViewsAccordionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4684c44915a5e2a1fef6505ad3219f2c9bd17f6b --- /dev/null +++ b/web/modules/views_accordion/tests/src/FunctionalJavascript/ViewsAccordionTest.php @@ -0,0 +1,55 @@ +<?php + +namespace Drupal\Tests\views_accordion\FunctionalJavascript; + +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; +use Drupal\Tests\node\Traits\NodeCreationTrait; + +/** + * Tests the JavaScript functionality of the Views Accordion module. + * + * @group views_accordion + */ +class ViewsAccordionTest extends JavascriptTestBase { + use NodeCreationTrait; + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'views_accordion_test', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + // Create a set of nodes for testing. + $this->createNode(); + $this->createNode(); + } + + /** + * Tests Views Accordion functionality. + */ + public function testViewsAccordion() { + $this->drupalGet('views-accordion-test'); + // Assert our JS settings are available. + $settings = $this->getDrupalSettings(); + $this->assertArrayHasKey('views_accordion', $settings, 'Views accordion JS settings avaialable'); + + // Assert that the first row is visible but not the second. + $this->getSession()->getDriver()->isVisible($this->cssSelectToXpath('#ui-id-2'), 'Row one is shown'); + $this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath('#ui-id-4')), 'Row two is collapsed'); + + // Assert that clicking the first row does not close it. + $this->click('#ui-id-1'); + $this->getSession()->getDriver()->isVisible($this->cssSelectToXpath('#ui-id-2'), 'Row one is stil shown'); + + // Assert the header icons are displayed in the correct place. + $this->getSession()->getDriver()->isVisible($this->cssSelectToXpath('#ui-id-1 span.ui-icon-triangle-1-s'), 'Active header icon is visible'); + $this->getSession()->getDriver()->isVisible($this->cssSelectToXpath('#ui-id-3 span.ui-icon-triangle-1-e'), 'Inactive header icon is visible'); + } + +} diff --git a/web/modules/views_accordion/views-accordion.js b/web/modules/views_accordion/views-accordion.js index de2ab0144838f6b2fc89ee9f53721123a1b5242d..f90c11bf5c97b798375880f01bb670e937d934fa 100644 --- a/web/modules/views_accordion/views-accordion.js +++ b/web/modules/views_accordion/views-accordion.js @@ -1,18 +1,22 @@ +/** + * @file + */ + (function ($, Drupal, drupalSettings) { 'use strict'; - Drupal.behaviors.views_accordion = { + Drupal.behaviors.views_accordion = { attach: function (context) { if (drupalSettings.views_accordion) { $.each(drupalSettings.views_accordion, function (id) { - var $display = $(this.display +':not(.ui-accordion)'); + var $display = $(this.display + ':not(.ui-accordion)'); /* The row count to be used if Row to display opened on start is set to random */ var row_count = 0; /* Prepare our markup for jquery ui accordion */ $(this.header, $display).each(function (i) { - // Wrap the accordion content within a div if necessary + // Wrap the accordion content within a div if necessary. if (!this.usegroupheader) { $(this).siblings().wrapAll('<div></div>'); row_count++; diff --git a/web/modules/views_accordion/views_accordion.info.yml b/web/modules/views_accordion/views_accordion.info.yml index 7fd4d1e2b151542d443969d2975a837b0c8eebf8..d0e1e35c842e32292d69239e6e4911b468705c2c 100644 --- a/web/modules/views_accordion/views_accordion.info.yml +++ b/web/modules/views_accordion/views_accordion.info.yml @@ -3,10 +3,10 @@ type: module description: 'Provides an accordion views display plugin.' # core: 8.x dependencies: - - views + - drupal:views -# Information added by Drupal.org packaging script on 2016-11-19 -version: '8.x-1.0-beta2' +# Information added by Drupal.org packaging script on 2018-03-25 +version: '8.x-1.1' core: '8.x' project: 'views_accordion' -datestamp: 1479568459 +datestamp: 1521988091 diff --git a/web/modules/views_accordion/views_accordion.module b/web/modules/views_accordion/views_accordion.module index d79c4693c6a1832af6fc9048efa78ea73beeffec..ff8666c16dd85d314fabf43498a65442af9ee278 100644 --- a/web/modules/views_accordion/views_accordion.module +++ b/web/modules/views_accordion/views_accordion.module @@ -1,37 +1,36 @@ <?php + /** * @file - * Provide an accordion display style for Views. - * - * This is a placeholder file so drupal will enable the module. All logic is contained in - * other files located with the module. + * Provides an accordion display style for Views. */ use Drupal\Core\Routing\RouteMatchInterface; /** - * Implementation of hook_help(). + * Implements hook_help(). */ function views_accordion_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.views_accordion': - $output = '<p>'. t('The Views Accordion module is a Views style plugin that displays the results in a JQuery accordion style. For more updated information visit the <a href="@link">Views Accordion documentation page</a>.', ['@link' => 'http://drupal.org/node/366263']) .'</p>'; + $output = '<p>' . t('The Views Accordion module is a Views style plugin that displays the results in a JQuery accordion style. For more updated information visit the <a href="@link">Views Accordion documentation page</a>.', ['@link' => 'http://drupal.org/node/366263']) . '</p>'; - $output .= '<h3>'. t('How to use the plugin') .'</h3>'; - $output .= t('<strong>IMPORTANT:</strong> The first field in order of appearance will be the one used as the "header" or "trigger" of the accordion action.') .'<br />'; + $output .= '<h3>' . t('How to use the plugin') . '</h3>'; + $output .= t('<strong>IMPORTANT:</strong> The first field in order of appearance will be the one used as the "header" or "trigger" of the accordion action.') . '<br />'; - $output .= '<h4>'. t('Your view must meet these requirements:') .'</h4>'; + $output .= '<h4>' . t('Your view must meet these requirements:') . '</h4>'; $output .= '<ul>'; - $output .= '<li>'. t('<em>Row style</em> must be set to <em>Fields</em>.') .'</li>'; + $output .= '<li>' . t('<em>Row style</em> must be set to <em>Fields</em>.') . '</li>'; $output .= '</ul>'; - $output .= '<h4>'. t('Choose <em>Views Accordion</em> in the <em>Style</em> dialog within your view, which will prompt you to configure the jquery.ui.accordion settings.') .'</h4>'; + $output .= '<h4>' . t('Choose <em>Views Accordion</em> in the <em>Style</em> dialog within your view, which will prompt you to configure the jquery.ui.accordion settings.') . '</h4>'; return $output; } } /** * Preprocess function for views_accordion_view template. + * * Default template: views-accordion-view.html.twig. * * @{inheritdoc}