summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-09-15 08:24:42 (GMT)
committerNathaniel Catchpole2016-09-15 08:24:42 (GMT)
commit2317a3968d427c4864c33d37ad26bf3339dfbab3 (patch)
treebcdfa1cab1680dd9a4ebdfb478c9621553ea2d1c
parentb39b29ad1483e80d4bdbfca31d2517cf4bad944b (diff)
Issue #2773333 by Berdir, Juterpillar, Wim Leers, Fabianx, renukakulkarni: Form validation errors, status messages on form submission are shown after page refresh when form is rendered in block
-rw-r--r--core/core.services.yml5
-rw-r--r--core/lib/Drupal/Core/Render/Element/StatusMessages.php7
-rw-r--r--core/modules/user/src/Tests/UserBlocksTest.php11
3 files changed, 20 insertions, 3 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index 6310c21..0b18c3b 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1591,10 +1591,13 @@ services:
tags:
- { name: mime_type_guesser }
lazy: true
+ # Currently needs to be public as it is called by
+ # \Drupal\Core\Render\Element\StatusMessages.
+ # @todo Consider making this service private again after
+ # https://www.drupal.org/node/2367555 lands.
render_placeholder_generator:
class: Drupal\Core\Render\PlaceholderGenerator
arguments: ['%renderer.config%']
- public: false
render_cache:
class: Drupal\Core\Render\PlaceholderingRenderCache
arguments: ['@request_stack', '@cache_factory', '@cache_contexts_manager', '@render_placeholder_generator']
diff --git a/core/lib/Drupal/Core/Render/Element/StatusMessages.php b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
index f026aa5..d16c245 100644
--- a/core/lib/Drupal/Core/Render/Element/StatusMessages.php
+++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
@@ -45,12 +45,15 @@ class StatusMessages extends RenderElement {
* The updated renderable array containing the placeholder.
*/
public static function generatePlaceholder(array $element) {
- $element['messages_placeholder'] = [
+ $element = [
'#lazy_builder' => [get_class() . '::renderMessages', [$element['#display']]],
'#create_placeholder' => TRUE,
];
- return $element;
+ // Directly create a placeholder as we need this to be placeholdered
+ // regardless if this is a POST or GET request.
+ // @todo remove this when https://www.drupal.org/node/2367555 lands.
+ return \Drupal::service('render_placeholder_generator')->createPlaceholder($element);
}
/**
diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php
index f66007e..9216a27 100644
--- a/core/modules/user/src/Tests/UserBlocksTest.php
+++ b/core/modules/user/src/Tests/UserBlocksTest.php
@@ -87,6 +87,17 @@ class UserBlocksTest extends WebTestBase {
$this->drupalPostForm('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
// Check that we remain on the site after login.
$this->assertUrl($user->url('canonical', ['absolute' => TRUE]), [], 'Redirected to user profile page after login from the frontpage');
+
+ // Verify that form validation errors are displayed immediately for forms
+ // in blocks and not on subsequent page requests.
+ $this->drupalLogout();
+ $edit = array();
+ $edit['name'] = 'foo';
+ $edit['pass'] = 'invalid password';
+ $this->drupalPostForm('filter/tips', $edit, t('Log in'));
+ $this->assertText(t('Unrecognized username or password. Forgot your password?'));
+ $this->drupalGet('filter/tips');
+ $this->assertNoText(t('Unrecognized username or password. Forgot your password?'));
}
/**