Commit 719ad7ba authored by catch's avatar catch
Browse files

Issue #3495881 by godotislate, bkosborne, catch, kushagra.goyal: Firefox...

Issue #3495881 by godotislate, bkosborne, catch, kushagra.goyal: Firefox retains form_build_id on form reloads, causing old form cache entry to be used and creating weird behavior for the Media Library widget

(cherry picked from commit f5a836d5)
parent 22ee1f02
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -729,6 +729,11 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) {
      // submitted form value appears literally, regardless of custom #tree
      // and #parents being set elsewhere.
      '#parents' => ['form_build_id'],
      // Certain browsers such as Firefox retain form input data after reload.
      // This can result in the form being in a strange state if the page is
      // reloaded after an AJAX request. Setting the form build ID field's
      // autocomplete off prevents the input from being retained.
      '#attributes' => ['autocomplete' => 'off'],
    ];

    // Add a token, based on either #token or form_id, to any form displayed to
+8 −1
Original line number Diff line number Diff line
@@ -40,7 +40,14 @@ protected function setUp(): void {
  protected function getFormBuildId(): string {
    // Ensure the hidden 'form_build_id' field is unique.
    $this->assertSession()->elementsCount('xpath', '//input[@name="form_build_id"]', 1);
    return (string) $this->assertSession()->hiddenFieldExists('form_build_id')->getAttribute('value');
    $form_build_id_element = $this->assertSession()->hiddenFieldExists('form_build_id');
    // Test that the autocomplete attribute is set to off to prevent Firefox and
    // similar browsers from retaining the form build ID on browser reload.
    // @todo Add actual testing that the form build ID is not retained once
    // Firefox is included in automated testing in
    // https://www.drupal.org/project/drupal/issues/3462680.
    $this->assertSame('off', $form_build_id_element->getAttribute('autocomplete'));
    return (string) $form_build_id_element->getAttribute('value');
  }

  /**