commit 313fb2e7297b4768da41a6c8869d013771f723ef Author: Joel Pittet Date: Wed Apr 1 23:06:01 2015 -0700 safemarkup fix and arrays diff --git a/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php index c29a994..d2ba75f 100644 --- a/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -73,8 +73,14 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st if (!empty($error_links)) { // We need to pass this through SafeMarkup::format() so // drupal_set_message() does not encode the links. + $message_error_links = ''; + $separator = ''; + foreach ($error_links as $error_link) { + $message_error_links .= $separator . SafeMarkup::escape($error_link); + $separator = ', '; + } $message = $this->formatPlural(count($error_links), '1 error has been found: !errors', '@count errors have been found: !errors', [ - '!errors' => implode(', ', $error_links), + '!errors' => SafeMarkup::set($message_error_links), ]); $this->drupalSetMessage($message, 'error'); } diff --git a/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php b/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php index 478e28d..dcdf5a8 100644 --- a/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php +++ b/core/lib/Drupal/Core/Render/Element/PasswordConfirm.php @@ -66,7 +66,7 @@ public static function processPasswordConfirm(&$element, FormStateInterface $for ); $element['#element_validate'] = array(array(get_called_class(), 'validatePasswordConfirm')); $element['#tree'] = TRUE; - $element['#theme_wrappers'] = array('fieldset'); + $element['#theme_wrappers'] = ['fieldset']; if (isset($element['#size'])) { $element['pass1']['#size'] = $element['pass2']['#size'] = $element['#size']; diff --git a/core/modules/system/templates/fieldset.html.twig b/core/modules/system/templates/fieldset.html.twig index 0823204..cf4e6fa 100644 --- a/core/modules/system/templates/fieldset.html.twig +++ b/core/modules/system/templates/fieldset.html.twig @@ -22,14 +22,7 @@ * @ingroup themeable */ #} -{% - set classes = [ - 'form-item', - 'form-wrapper', - errors ? 'form-error', - ] -%} - + {% if errors %}
{{ errors }} diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php index 76203a5..29f4203 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/src/Tests/UserBlocksTest.php @@ -45,7 +45,6 @@ protected function setUp() { function testUserLoginBlock() { // Make sure the validation error is displayed when try to login with // invalid username/password. - $edit = array(); $edit['name'] = $this->randomMachineName(); $edit['pass'] = $this->randomMachineName(); $this->drupalPostForm('node', $edit, t('Log in')); diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php index 95cef7f..2769506 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php @@ -37,19 +37,19 @@ public function testDisplayErrorMessages() { ->method('drupalSetMessage') ->with('2 errors have been found: Test 1, Test 2', 'error'); - $form = array( - '#parents' => array(), - ); - $form['test1'] = array( + $form = [ + '#parents' => [], + ]; + $form['test1'] = [ '#type' => 'textfield', '#title' => 'Test 1', - '#parents' => array('test1'), - ); - $form['test2'] = array( + '#parents' => ['test1'], + ]; + $form['test2'] = [ '#type' => 'textfield', '#title' => 'Test 2', - '#parents' => array('test2'), - ); + '#parents' => ['test2'], + ]; $form_state = new FormState(); $form_state->setErrorByName('test1', 'invalid'); $form_state->setErrorByName('test2', 'invalid'); @@ -68,14 +68,14 @@ public function testSetElementErrorsFromFormState() { ->setMethods(['drupalSetMessage']) ->getMock(); - $form = array( - '#parents' => array(), - ); - $form['test'] = array( + $form = [ + '#parents' => [], + ]; + $form['test'] = [ '#type' => 'textfield', '#title' => 'Test', - '#parents' => array('test'), - ); + '#parents' => ['test'], + ]; $form_state = new FormState(); $form_state->setErrorByName('test', 'invalid'); $form_error_handler->handleFormErrors($form, $form_state); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 461e618..ac42b8f 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -206,7 +206,7 @@ public function getStringTranslationStub() { ->will($this->returnCallback('Drupal\Component\Utility\SafeMarkup::format')); $translation->expects($this->any()) ->method('formatPlural') - ->willReturnCallback(function ($count, $singular, $plural, array $args = array(), array $options = array()) { + ->willReturnCallback(function ($count, $singular, $plural, array $args = [], array $options = []) { return $count === 1 ? SafeMarkup::format($singular, $args) : SafeMarkup::format($plural, $args + ['@count' => $count]); }); return $translation; diff --git a/core/themes/classy/templates/form/fieldset.html.twig b/core/themes/classy/templates/form/fieldset.html.twig index 4a7b2f5..aa14b30 100644 --- a/core/themes/classy/templates/form/fieldset.html.twig +++ b/core/themes/classy/templates/form/fieldset.html.twig @@ -20,14 +20,7 @@ * @see template_preprocess_fieldset() */ #} -{% - set classes = [ - 'form-item', - 'form-wrapper', - errors ? 'form-error', - ] -%} - + {% if errors %}
{{ errors }} diff --git a/core/themes/seven/templates/fieldset.html.twig b/core/themes/seven/templates/fieldset.html.twig index 0476f4b..a49c993 100644 --- a/core/themes/seven/templates/fieldset.html.twig +++ b/core/themes/seven/templates/fieldset.html.twig @@ -22,14 +22,8 @@ * @ingroup themeable */ #} -{% - set classes = [ - 'form-item', - 'form-wrapper', - errors ? 'form-error', - ] %} - + {% set legend_span_classes = [ 'fieldset-legend',