Problem/Motivation
When using a heredoc or nowdoc inside a call to the t function, validation gives warning: 'Only string literals should be passed to t() where possible (Drupal.Semantics.FunctionT.NotLiteralString)'. Since heredoc and nowdoc are string literals they should be supported or the error message changed.
Steps to reproduce
Create a render array with a heredoc inside the t function and then validate it. e.g.:
$form['tic'] = [
'#markup' => $this->t(<<<'TEXT'
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer
placerat id justo nec porttitor. Maecenas at auctor nisi, vitae tempor
nulla. Donec nisl est, hendrerit ac odio id, maximus bibendum sem. In
sollicitudin, lorem vitae eleifend congue, nulla enim semper ante, in
vulputate libero orci in ligula. Ut facilisis quam augue, sed rhoncus
nisl lobortis a. Curabitur tempor lectus ut suscipit venenatis. Donec
semper neque eu orci blandit convallis. Morbi arcu turpis, condimentum
vitae sollicitudin dapibus, commodo et nisl. Nam sed consectetur enim.
Duis a tellus nisi. Fusce egestas varius convallis.
TEXT
),
];
Comments
Comment #2
kensuke-imamura commentedI fixed nowdoc's case and it seems to work. It is harder to fix heredoc's because heredoc can contain variables within it. More complex detection logic is needed.
Comment #4
kensuke-imamura commentedComment #6
klausiMerged, thanks a lot!