Skip to content
Snippets Groups Projects
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
Branches
Tags
9 merge requests!4488Issue #3376281: Random machine names no longer need to be wrapped in strtolower(),!3149Issue #3282285: Email "" does not comply with addr-spec of RFC 2822,!3000Issue #793660: Check for failure of hook_install,!2940Issue #3320240: Entity count query returns a string instead of int,!2937Issue #3315245: Order of languages overrides default language fallback,!2877Issue #3056652 by yogeshmpawar, mashermike, aalin, ranjith_kumar_k_u: Link...,!1627Issue #3082958: Add gitignore(s) to composer-ready project templates,!1014Issue #3226806: Move filter implementations from filter.module to plugin classes,!939Issue #2971209: Allow the MediaLibraryUiBuilder service to use an alternative view display
......@@ -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.
$form_state->addBuildInfo('base_form_id', $this->getBaseFormId());
// 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 = [];
......
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
<?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);
}
<?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');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment