Verified Commit ad75505b authored by Dave Long's avatar Dave Long
Browse files

Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/changing...

Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/changing “Reference method” in Views EntityReference filter extra settings

(cherry picked from commit a7b619c8)
parent 7abe563e
Loading
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -360,14 +360,13 @@ public function validateExtraOptionsForm($form, FormStateInterface $form_state):
   */
  public function submitExtraOptionsForm($form, FormStateInterface $form_state): void {
    $sub_handler = $form_state->getValue('options')['sub_handler'];

    // Ensure that only the select sub handler option is saved.
    // Unset sub handler settings that are not selected so they are not saved.
    // ConfigHandlerExtra::submitForm will set the selected sub handler's
    // settings.
    foreach (array_keys($this->getSubHandlerOptions()) as $sub_handler_option) {
      if ($sub_handler_option == $sub_handler) {
        $this->options['sub_handler_settings'] = $this->options[static::SUBFORM_PREFIX . $sub_handler_option];
      }
      if (isset($this->options[static::SUBFORM_PREFIX . $sub_handler_option])) {
        unset($this->options[static::SUBFORM_PREFIX . $sub_handler_option]);
      $subform_key = static::SUBFORM_PREFIX . $sub_handler_option;
      if ($sub_handler_option !== $sub_handler && isset($this->options[$subform_key])) {
        unset($this->options[$subform_key]);
      }
    }
  }
+13 −0
Original line number Diff line number Diff line
@@ -100,6 +100,19 @@ public function testFilterUi(): void {
      $this->assertEquals($options[$i]['label'], $entity->label(), $message);
      $i++;
    }

    // Change Reference method to the test_entity_reference entity reference
    // view and ensure options are updated to only contain the one view result.
    $this->drupalGet('admin/structure/views/nojs/handler-extra/test_filter_entity_reference/default/filter/field_test_target_id');
    $edit = [
      'options[sub_handler]' => 'views',
      'options[reference_views][view][view_and_display]' => 'test_entity_reference:entity_reference',
    ];
    $this->submitForm($edit, 'Apply');
    $this->drupalGet('admin/structure/views/nojs/handler/test_filter_entity_reference/default/filter/field_test_target_id');
    $options = $this->getUiOptions();
    $this->assertCount(1, $options);
    $this->assertEquals('Article 0', $options[0]['label']);
  }

  /**