Verified Commit 2be5351f authored by Jibran Ijaz's avatar Jibran Ijaz Committed by Jibran Ijaz
Browse files

Issue #3149274 by jibran: Make the module Drupal 9 compatible

parent f4c75aaa
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
# Schema for the views_fieldset style plugins.
views.style.fieldset:
  type: views_style
  label: 'Fieldset'
  mapping:
    title:
      type:  string
      label: 'Fieldset Title'
    description:
      type: string
      label: 'Fieldset Description'
+11 −27
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains \Drupal\views_fieldset\Plugin\views\style\FieldsetStyle.
 */

namespace Drupal\views_fieldset\Plugin\views\style;

use Drupal\Core\Form\FormStateInterface;
@@ -26,33 +21,22 @@ use Drupal\views\Plugin\views\style\StylePluginBase;
class FieldsetStyle extends StylePluginBase {

  /**
   * Does the style plugin allows to use style plugins.
   *
   * @var bool
   * {@inheritdoc}
   */
  protected $usesRowPlugin = TRUE;

  /**
   * Does the style plugin support custom css class for the rows.
   *
   * @var bool
   * {@inheritdoc}
   */
  protected $usesRowClass = TRUE;

  /**
   * Does the style plugin support grouping of rows.
   *
   * @var bool
   * {@inheritdoc}
   */
  protected $usesGrouping = FALSE;

  /**
   * Does the style plugin for itself support to add fields to it's output.
   *
   * This option only makes sense on style plugins without row plugins, like
   * for example table.
   *
   * @var bool
   * {@inheritdoc}
   */
  protected $usesFields = TRUE;

@@ -62,8 +46,8 @@ class FieldsetStyle extends StylePluginBase {
  protected function defineOptions() {

    $options = parent::defineOptions();
    $options['title'] = array('default' => '');
    $options['description'] = array('default' => '');
    $options['title'] = ['default' => ''];
    $options['description'] = ['default' => ''];

    return $options;
  }
@@ -74,27 +58,27 @@ class FieldsetStyle extends StylePluginBase {
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {

    parent::buildOptionsForm($form, $form_state);
    $options = array('' => $this->t('- None -'));
    $options = ['' => $this->t('- None -')];
    $field_labels = $this->displayHandler->getFieldLabels(TRUE);
    $options += $field_labels;

    $form['title'] = array(
    $form['title'] = [
      '#type' => 'select',
      '#title' => $this->t('Fieldset Title'),
      '#options' => $options,
      '#default_value' => $this->options['title'],
      '#description' => $this->t('Choose the title of fieldset.'),
      '#weight' => -48,
    );
    ];

    $form['description'] = array(
    $form['description'] = [
      '#type' => 'select',
      '#title' => $this->t('Fieldset Description'),
      '#options' => $options,
      '#default_value' => $this->options['description'],
      '#description' => $this->t('Optional fieldset description.'),
      '#weight' => -47,
    );
    ];
  }

}
+207 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - views_fieldset
    - views_test_data
id: test_views_fieldset_style_fieldset
label: ''
module: views
description: ''
tag: ''
base_table: views_test_data
base_field: id
display:
  default:
    id: default
    display_title: Default
    display_plugin: default
    position: null
    display_options:
      fields:
        name:
          id: name
          table: views_test_data
          field: name
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: true
          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
        id:
          id: id
          table: views_test_data
          field: id
          relationship: none
          group_type: group
          admin_label: ''
          plugin_id: numeric
          label: ''
          exclude: true
          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
          set_precision: false
          precision: 0
          decimal: .
          separator: ''
          format_plural: false
          format_plural_string: !!binary MQNAY291bnQ=
          prefix: ''
          suffix: ''
        job:
          id: job
          table: views_test_data
          field: job
          relationship: none
          group_type: group
          admin_label: ''
          plugin_id: standard
          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
      pager:
        type: full
        options: {  }
      exposed_form:
        type: basic
        options: {  }
      access:
        type: none
        options: {  }
      cache:
        type: tag
        options: {  }
      style:
        type: fieldset
        options:
          row_class: ''
          default_row_class: true
          title: id
          description: name
      row:
        type: fields
        options: {  }
      query:
        type: views_query
        options: {  }
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_interface'
        - url.query_args
      tags: {  }
+9 −0
Original line number Diff line number Diff line
name: 'Views fieldset test views'
type: module
description: 'Provides default views for views_fieldset tests.'
package: Testing
core_version_requirement: ^8 || ^9
hidden: TRUE
dependencies:
  - drupal:views_fieldset
  - drupal:views
+69 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\views_fieldset\Kernel\Plugin;

use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;

/**
 * Tests the field_set style plugin.
 *
 * @group views
 * @see \Drupal\views_fieldset\Plugin\views\style\FieldsetStyle
 */
class ViewsFieldsetStyleFieldsetTest extends ViewsKernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'views_fieldset',
    'views_fieldset_test_views',
  ];

  /**
   * {@inheritdoc}
   */
  public static $testViews = ['test_views_fieldset_style_fieldset'];

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);
    $this->installConfig(['views_fieldset', 'views_fieldset_test_views']);

    ViewTestData::createTestViews(get_class($this), ['views_fieldset_test_views']);
  }

  /**
   * Make sure that the field_set style markup is correct.
   */
  public function testStylePluginOptions() {
    $view = Views::getView('test_views_fieldset_style_fieldset');
    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);

    // Check that fieldset element is present.
    $this->assertStringContainsString('<fieldset', $output, 'The fieldset element is present.');
    $this->assertStringContainsString('<legend>', $output, 'The fieldset element has a title.');
    $this->assertStringContainsString('class="description"', $output, 'The fieldset element has description.');
    $this->assertStringContainsString('class="field-content"', $output, 'The fieldset element has content.');


    // Unset tile and description in style options.
    $view->style_plugin->options['title'] = '';
    $view->style_plugin->options['description'] = '';

    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);

    // Check that fieldset element is present.
    $this->assertStringContainsString('<fieldset', $output, 'The fieldset element is present.');
    $this->assertStringContainsString('<span class="fieldset-legend"></span>', $output, 'The fieldset element has no title.');
    $this->assertStringNotContainsString('class="description"', $output, 'The fieldset element has no description.');
    $this->assertStringContainsString('class="field-content"', $output, 'The fieldset element has content.');
  }

}
Loading