On FormattableMarkup::placeholderFormat(), the secure examples are the following.
$this->placeholderFormat('<a href=":foo">link text</a>, ['@foo' => $some_variable]);
$this->placeholderFormat('<a href=":foo" title="static text">link text</a>, ['@foo' => $some_variable]);
$this->placeholderFormat('<a href=":foo">@foo</a>, ['@foo' => $some_variable]);
// Use : placeholder inside an HTML tag.
$this->placeholderFormat('<img src=":foo" />, ['@foo' => '/image.png']);
The placeholders used in the strings are different from the placeholders in the array passed as second argument. For example, the first example uses :foo as placeholder, but the array contains '@foo'. Furthermore, the literal strings passed as first argument do not include string delimiters.
The correct examples are the following one.
$this->placeholderFormat('<a href=":foo">link text</a>', [':foo' => $some_variable]);
$this->placeholderFormat('<a href=":foo" title="static text">link text</a>', [':foo' => $some_variable]);
$this->placeholderFormat('<a href=":foo">@foo</a>', [':foo' => $some_variable]);
// Use : placeholder inside an HTML tag.
$this->placeholderFormat('<img src=":foo" />', [':foo' => '/image.png']);Issue fork drupal-3498468
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:
- 3498468-the-documentation-for
changes, plain diff MR !11912
Comments
Comment #2
wombatbuddy commentedComment #3
poker10 commentedThis seems to be caused by changes from #2580505: Improve FormattableMarkup documentation. Tagging as novice.
Comment #4
avpadernoComment #5
avpadernoComment #8
nexusnovaz commentedI've made the changes in MR !11912 though there I have a question for Line 118. Currently the correct usage in the html tag should be
href=":foo", but then@foois used as the placeholder for the text surrounded by the html tag. However, there is no substitution for this in the array. Should the@fooalso be changed to use:fooas it would appear they should have the same output?Comment #9
avpadernoIn
'<a href=":foo">@foo</a>,@foocan either be left, or replaced. (I would use'<a href=":foo">link text</a>' like the other examples.)Also, in
$this->placeholderFormat('<a href=":foo">@foo</a>, ['@foo' => $some_variable]);a string delimiter is missing. The correct code is the following one.$this->placeholderFormat('<a href=":foo">link text</a>', [':foo' => $some_variable]);Comment #10
nexusnovaz commentedNice, thanks for that @avpaderno. I've made those changes and i believe it is all correct. Please can someone review MR !11912
Comment #11
avpadernoThe changes in the MR are correct.
Comment #12
quietone commented@poker10, thanks for searching for where this was introduced. That is always helpful.
Updated credit. I will commit this presently.
Comment #15
quietone commented