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
  ),
];
CommentFileSizeAuthor
#2 nowdoc.patch1.91 KBkensuke-imamura

Issue fork coder-3562081

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kwfinken created an issue. See original summary.

kensuke-imamura’s picture

StatusFileSize
new1.91 KB

I 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.

kensuke-imamura’s picture

Status: Active » Needs review

klausi made their first commit to this issue’s fork.

klausi’s picture

Version: 8.3.x-dev » 9.x-dev
Status: Needs review » Fixed

Merged, thanks a lot!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.