issue/3456149: Fixed translation string in ConfigFormBase
Merge request reports
Activity
added 45 commits
-
4d7b433c...df700a8d - 43 commits from branch
project:11.x
- bdbc4f4f - issue/3456149: Fixed translation string in ConfigFormBase
- 7c511509 - Update comment slightly,
-
4d7b433c...df700a8d - 43 commits from branch
added 10 commits
-
7c511509...2e3d1783 - 9 commits from branch
project:11.x
- a168d50a - Merge branch '11.x' into '3456149-fix-translation-string'
-
7c511509...2e3d1783 - 9 commits from branch
added 1 commit
- 684d98af - issue/3456149: revert unrelated change after resolving conflcits.
291 291 '@validation_error_message' => $violation->getMessage(), 292 292 ]); 293 293 } 294 return $this->t(implode("\n", $transformed_message_parts)); 294 $transformed_message = implode("\n", $transformed_message_parts); 295 // We use \Drupal\Component\Render\FormattableMarkup directly here, 296 // rather than use t() to ensure proper handling of content and 297 // prevent unintended translation. 298 return new FormattableMarkup('%transformed_message', ['%transformed_message' => $transformed_message]); - Comment on lines +294 to +298
This is going to wrap the message in em tags because of the percentage. I think this should be:
294 $transformed_message = implode("\n", $transformed_message_parts); 295 // We use \Drupal\Component\Render\FormattableMarkup directly here, 296 // rather than use t() to ensure proper handling of content and 297 // prevent unintended translation. 298 return new FormattableMarkup('%transformed_message', ['%transformed_message' => $transformed_message]); 294 $transformed_message = implode("\n", $transformed_message_parts); 295 // We use \Drupal\Component\Render\FormattableMarkup directly here, 296 // rather than use t() to ensure proper handling of content and 297 // prevent unintended translation. 298 return new FormattableMarkup(implode("\n", $transformed_message_parts)); But actually I think this would be even better if we did
return Markup::create(implode("\n", $transformed_message_parts));
- also I think the return type could be MarkupInterface or \StringableThe comment should explain that this is safe because all input has been escaped by t() above.
changed this line in version 6 of the diff
added 1 commit
- 6ee52743 - issue/3456149: Applied suggestions ConfigFormBase
276 277 * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations 277 278 * The list of constraint violations that apply to this form element. 278 279 * 279 * @return \Drupal\Core\StringTranslation\TranslatableMarkup 280 * @return \Drupal\Component\Render\MarkupInterface|string 281 * The rendered HTML. 280 282 */ 281 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): TranslatableMarkup { 283 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): MarkupInterface|string { I have taken this reference from:
core/lib/Drupal/Core/Render/Renderer.php
, where both MarkupInterface and string returned in this manner.For now as per suggestion need to use one, used MarkupInterface in return statement.
Edited by Pooja Sharmachanged this line in version 7 of the diff
added 1 commit
- 97d7e04c - issue/3456149: Applied suggestion ConfigFormBase
added 1 commit
- e32a769f - issue/3456149: Applied suggestions ConfigFormBase
276 277 * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations 277 278 * The list of constraint violations that apply to this form element. 278 279 * 279 * @return \Drupal\Core\StringTranslation\TranslatableMarkup 280 * @return \Drupal\Component\Render\MarkupInterface|\Stringable 281 * The rendered HTML. 280 282 */ 281 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): TranslatableMarkup { 283 protected function formatMultipleViolationsMessage(string $form_element_name, array $violations): MarkupInterface|\Stringable { - Comment on lines -279 to +283
Nah by OR I meant either or... let's make a choice. Let's go for \Stringable. MarkupInterface enforces that you implement __toString() which is the same as the pseudo-interface \Stringable so \Drupal\Component\Render\MarkupInterface|\Stringable is kinda pointless. How I guess if someone has overridden this method and has a return typehint on TranslatableMarkup then this will still work because it would be a narrowing of return types so let's still with this.