diff --git a/core/core.services.yml b/core/core.services.yml index 6310c211b55e871650442ad338795517ffe6b24d..0b18c3b19357c19e1ef75b3f6d36b1c95d54a6ff 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 f026aa5c58a935e0ccc4ae5ec71bcd79bc023001..d16c245a1d819228100b5e36367af73d69fad126 100644 --- a/core/lib/Drupal/Core/Render/Element/StatusMessages.php +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php @@ -45,12 +45,15 @@ public function getInfo() { * 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 f66007e2d8ad19ec2079236dff479a2653859383..9216a2765d1f885f4a82d81a33ecfdab5ecdc6f4 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/src/Tests/UserBlocksTest.php @@ -87,6 +87,17 @@ function testUserLoginBlock() { $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?')); } /**