Unverified Commit f1f4db70 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #2339921 Undefined variable: groups in...

fix: #2339921 Undefined variable: groups in \Drupal\views\Plugin\views\filter\FilterPluginBase::groupForm

By: dawehner
By: almaudoh
By: adci_contributor
By: alexpott
By: aerozeppelin
By: quietone
By: pcambra
By: hayk hayrapetyan
By: acbramley
By: godotislate
(cherry picked from commit b2c0b060)
parent f6db08c6
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -40525,12 +40525,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/views/src/Plugin/views/filter/FilterPluginBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Variable \\$groups might not be defined\\.$#',
	'identifier' => 'variable.undefined',
	'count' => 1,
	'path' => __DIR__ . '/modules/views/src/Plugin/views/filter/FilterPluginBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\views\\\\Plugin\\\\views\\\\filter\\\\GroupByNumeric\\:\\:adminLabel\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+11 −7
Original line number Diff line number Diff line
@@ -990,6 +990,7 @@ protected function buildGroupOptions() {
   * filter.
   */
  public function groupForm(&$form, FormStateInterface $form_state) {
    $groups = [];
    if (!empty($this->options['group_info']['optional']) && !$this->multipleExposedInput()) {
      $groups = ['All' => $this->t('- Any -')];
    }
@@ -1500,16 +1501,20 @@ public function convertExposedInput(&$input, $selected_group_id = NULL) {
      if (!empty($selected_group_id)) {
        $selected_group = $selected_group_id;
      }
      else {
      elseif (isset($input[$this->options['group_info']['identifier']])) {
        $selected_group = $input[$this->options['group_info']['identifier']];
      }
      else {
        return FALSE;
      }

      if ($selected_group == 'All' && !empty($this->options['group_info']['optional'])) {
        return NULL;
      }
      if ($selected_group != 'All' && empty($this->options['group_info']['group_items'][$selected_group])) {
        return FALSE;
      }
      if (isset($selected_group) && isset($this->options['group_info']['group_items'][$selected_group])) {
      if (isset($this->options['group_info']['group_items'][$selected_group])) {
        $selected_group_options = $this->options['group_info']['group_items'][$selected_group];

        $operator_id = $this->options['expose']['operator'];
@@ -1526,11 +1531,10 @@ public function convertExposedInput(&$input, $selected_group_id = NULL) {
        $this->group_info = $input[$this->options['group_info']['identifier']];
        return TRUE;
      }
      else {

      return FALSE;
    }
  }
  }

  /**
   * Group multiple exposed input.
@@ -1615,10 +1619,10 @@ public function acceptExposedInput($input) {

    if (!empty($this->options['expose']['identifier'])) {
      if ($this->options['is_grouped']) {
        $value = $input[$this->options['group_info']['identifier']];
        $value = $input[$this->options['group_info']['identifier']] ?? NULL;
      }
      else {
        $value = $input[$this->options['expose']['identifier']];
        $value = $input[$this->options['expose']['identifier']] ?? NULL;
      }

      // Various ways to check for the absence of non-required input.
+160 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - node
id: test_empty_group_form
label: test_empty_group_form
module: node
description: ''
tag: default
base_table: node_field_data
base_field: nid
display:
  default:
    id: default
    display_title: Default
    display_plugin: default
    position: 0
    display_options:
      title: Content
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          entity_type: node
          entity_field: title
          plugin_id: field
          label: Title
          exclude: false
          alter:
            alter_text: false
          element_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          type: string
          settings:
            link_to_entity: true
      pager:
        type: none
        options:
          offset: 0
      exposed_form:
        type: basic
        options:
          submit_button: Filter
          reset_button: true
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      access:
        type: none
        options: {  }
      cache:
        type: tag
      empty: {  }
      sorts: {  }
      arguments: {  }
      filters:
        status:
          id: status
          table: node_field_data
          field: status
          relationship: none
          group_type: group
          admin_label: ''
          entity_type: node
          entity_field: status
          plugin_id: boolean
          operator: '='
          value: '1'
          group: 1
          exposed: true
          expose:
            operator_id: ''
            label: Status
            description: ''
            use_operator: false
            operator: status_op
            operator_limit_selection: false
            operator_list: {  }
            identifier: status
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
          is_grouped: true
          group_info:
            label: 'Published status'
            description: ''
            identifier: status
            optional: false
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
      filter_groups:
        operator: AND
        groups:
          1: AND
      style:
        type: default
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
      row:
        type: fields
      query:
        type: views_query
      relationships: {  }
      show_admin_links: false
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
      tags: {  }
  page_1:
    id: page_1
    display_title: Page
    display_plugin: page
    position: 1
    display_options:
      display_extenders: {  }
      path: test-empty-groups
      menu:
        type: none
        title: Content
        description: ''
        weight: -10
        expanded: false
        menu_name: admin
        parent: ''
        context: '0'
      tab_options:
        type: normal
        title: Content
        description: 'Find and manage content'
        weight: -10
        menu_name: admin
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url
        - 'user.node_grants:view'
      tags: {  }
+42 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\views\Functional;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests the filter group form.
 */
#[Group('views')]
#[RunTestsInSeparateProcesses]
class FilterGroupFormTest extends ViewTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static array $testViews = ['test_empty_group_form'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['node'];

  /**
   * Tests a view with a grouped filter with empty options.
   */
  public function testFilterGroupFormEmpty(): void {
    $this->drupalGet('/test-empty-groups');
    $this->assertSession()->statusCodeEquals(200);
  }

}