Problem/Motivation

How to reproduce it:

  1. Enable the config_translation
  2. Add a new language to the site
  3. Create a list field with at least 3 options and set cardinality to 2 on any content type
  4. Use the checkboxes widget for that field
  5. Translate the field label
  6. Translate the core validation contraint '%name: this field cannot hold more than @count values.'
  7. Submit the node form of the content type with 3 options

The resulting error

The problem is apparently caused due to a nested string translation object of the field label within the translation string object of the constraint itself. Here the details:

The website encountered an unexpected error. Please try again later.
User error: InvalidArgumentException thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /core/lib/Drupal/Core/Database/Connection.php on line 719: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (line 25 of core/lib/Drupal/Component/Utility/ToStringTrait.php).
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
drupal_set_message(Object, 'error', )
Drupal\Core\Form\FormErrorHandler->drupalSetMessage(Object, 'error')
Drupal\Core\Form\FormErrorHandler->displayErrorMessages(Array, Object)
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object)
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'user_form')
Drupal\Core\Form\FormValidator->validateForm('user_form', Array, Object)
Drupal\Core\Form\FormBuilder->processForm('user_form', Array, Object)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

The expected result

The validation constraint should be displayed translated (including the field's label)

Proposed resolution

Case the maxMessage to string in FieldItemList::getConstraints(). A UI test for this wouldn't hurt either.

Comments

s_leu created an issue. See original summary.

s_leu’s picture

Status: Active » Closed (duplicate)
alexpott’s picture

Priority: Normal » Critical
Status: Closed (duplicate) » Active

We're going to put a fix in before RC. This is critical bug because it WSOD's and presents the user with no chance of recovery.

alexpott’s picture

Status: Active » Closed (duplicate)

Discussed some more with @catch we decided to go for the full fix in #2570285: Make sure TranslatableMarkup accepts string values only