Commit a9f47fff authored by catch's avatar catch

Issue #2773333 by Berdir, Juterpillar, Wim Leers, Fabianx, renukakulkarni:...

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

(cherry picked from commit 2317a396)
parent 58afbce2
......@@ -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']
......
......@@ -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);
}
/**
......
......@@ -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?'));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment