Verified Commit 12351e68 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2875987 by raman.b, smustgrave, ericgsmith, anushrikumari, Lendude:...

Issue #2875987 by raman.b, smustgrave, ericgsmith, anushrikumari, Lendude: Form alter hook called twice for views forms without view arguments

(cherry picked from commit c723f4b7)
(cherry picked from commit 112631ae)
parent 78a5362b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -148,8 +148,11 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu
    }
    $form_state->set(['step_controller', 'views_form_views_form'], 'Drupal\views\Form\ViewsFormMainForm');

    // Add the base form ID.
    // Views forms without view arguments return the same Base Form ID and
    // Form ID. Base form ID should only be added when different.
    if ($this->getBaseFormId() !== $this->getFormId()) {
      $form_state->addBuildInfo('base_form_id', $this->getBaseFormId());
    }

    $form = [];

+8 −0
Original line number Diff line number Diff line
name: 'Views Form Test'
type: module
description: 'Provides hook to alter views form for testing purposes.'
package: Testing
version: VERSION
dependencies:
  - drupal:views
  - drupal:media
+17 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Hook implementations for this module.
 */

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function views_form_test_form_views_form_media_media_page_list_alter(&$form, FormStateInterface $form_state, $form_id) {
  $state = \Drupal::state();
  $count = $state->get('hook_form_BASE_FORM_ID_alter_count', 0);
  $state->set('hook_form_BASE_FORM_ID_alter_count', $count + 1);
}
+32 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\views\Functional;

/**
 * Tests hook_form_BASE_FORM_ID_alter for a ViewsForm.
 *
 * @group views
 */
class ViewsFormAlterTest extends ViewTestBase {

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

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

  /**
   * Tests hook_form_BASE_FORM_ID_alter for a ViewsForm.
   */
  public function testViewsFormAlter() {
    $this->drupalLogin($this->createUser(['access media overview']));
    $this->drupalGet('admin/content/media');
    $count = $this->container->get('state')->get('hook_form_BASE_FORM_ID_alter_count');
    $this->assertEquals(1, $count, 'hook_form_BASE_FORM_ID_alter was invoked only once');
  }

}