- Issue created by @kferencz91
- πΊπΏUzbekistan biarr
I confirm this error when installing this module on fresh Drupal 10 installation. Any views with 'Views Conditional' resulting ```Invalid placeholder (context) with string:..``` .
I'm hitting this issue too. Just updated to D10 and on Views 1.5.
User warning: Invalid placeholder (context) with string: "" in Drupal\Component\Render\FormattableMarkup::placeholderFormat() (line 245 of core/lib/Drupal/Component/Render/FormattableMarkup.php).
- π¦πΊAustralia steventpmc
Not really a solution, but in the meantime I've used the Disable Messages module to stop these error messages from rendering on the front-end to users. https://www.drupal.org/project/disable_messages β
This might help someone in the short term.
- π¨π·Costa Rica maxmendez
Hi,
I faced with this warning today, in my case the problem was trigger by the options 'Translate "Then" output' and 'Translate "Or" output', i disabled both options and disappear, in my case i does not neet translation of the values and this could be a clue to solve the root problem.
- π§πͺBelgium fbreckx Antwerp
I also have this problem. Turning off the messages is not really a help, as the translation does not come through anyway.
- πΊπΈUnited States rishi kulshreshtha
The solution provided at #6 works for those who don't need translation of the values.
- πΊπΈUnited States TolstoyDotCom L.A.
That might be related to this, please test the merge request: https://www.drupal.org/project/drupal/issues/3173103#comment-15128512 π False positives when identifying what is a placeholder, for deprecation error Fixed
- πΊπΈUnited States msangha
I am also having the same issue related to views conditional field in my views. This is after I upgraded from D9.5.x do D10.1.x.
I was able to create my own patch but after core gets updated the changes are over-ridden.
I modified this file:
core/lib/Drupal/Component/Render/FormattableMarkup.phpThis is the function I modified. I added the switch 'c':
protected static function placeholderFormat($string, array $args) { // Transform arguments before inserting them. foreach ($args as $key => $value) { if (is_null($value)) { // It's probably a bug to provide a null value for the placeholder arg, // and in D11 this will no longer be allowed. When this trigger_error // is removed, also remove isset $value checks inside the switch{} // below. @trigger_error(sprintf('Deprecated NULL placeholder value for key (%s) in: "%s". This will throw a PHP error in drupal:11.0.0. See https://www.drupal.org/node/3318826', (string) $key, (string) $string), E_USER_DEPRECATED); $value = ''; } switch ($key[0]) { case '@': // Escape if the value is not an object from a class that implements // \Drupal\Component\Render\MarkupInterface, for example strings will // be escaped. // Strings that are safe within HTML fragments, but not within other // contexts, may still be an instance of // \Drupal\Component\Render\MarkupInterface, so this placeholder type // must not be used within HTML attributes, JavaScript, or CSS. $args[$key] = static::placeholderEscape($value); break; case ':': // Strip URL protocols that can be XSS vectors. $value = UrlHelper::stripDangerousProtocols($value); // Escape unconditionally, without checking whether the value is an // instance of \Drupal\Component\Render\MarkupInterface. This forces // characters that are unsafe for use in an "href" HTML attribute to // be encoded. If a caller wants to pass a value that is extracted // from HTML and therefore is already HTML encoded, it must invoke // \Drupal\Component\Render\OutputStrategyInterface::renderFromHtml() // on it prior to passing it in as a placeholder value of this type. // @todo Add some advice and stronger warnings. // https://www.drupal.org/node/2569041. $args[$key] = Html::escape($value); break; case '%': // Similarly to @, escape non-safe values. Also, add wrapping markup // in order to render as a placeholder. Not for use within attributes, // per the warning above about // \Drupal\Component\Render\MarkupInterface and also due to the // wrapping markup. $args[$key] = '<em class="placeholder">' . static::placeholderEscape($value) . '</em>'; break; case 'c': // 7-7-23 Copied Case @ because was getting placholder error after upgrade to D10.1.1 $args[$key] = static::placeholderEscape($value); break; default: // Warn for random variables that won't be replaced. trigger_error(sprintf('Invalid placeholder (%s) with string: "%s"', $key, $string), E_USER_WARNING); // No replacement possible therefore we can discard the argument. unset($args[$key]); break; } }
I test merge request mentioned in #10. Success! Error message no longer flooding the logs!
- πΈπ¦Saudi Arabia ishore
#6 and #10 did not work for me, but #11 does. Thanks!
- πΊπΈUnited States TolstoyDotCom L.A.
Some of the proposed solutions assume the problematic keys will start with a certain letter or be of a set of strings. The solution in #10 is more general purpose. If there's a problem using it, please post the details.
- π¨π¦Canada chrisck BC, Canada
@TolstoyDoyCom Thanks for your MR in the other issue. I'm confirming the MR fixes my issue, as reported here.
This looks to be a general problem in core and perhaps not specific to views_conditional.
- π¬π§United Kingdom jonathan1055
π False positives when identifying what is a placeholder, for deprecation error Fixed has been fixed. Does this solve the problem?
- π©πͺGermany marcoka
#17 No the core patch does not fix this. Applied it to my drupal 10.1.
#14 Yes, your changes in the merge request will work, no more warnings in the drupal logs. - πΊπΈUnited States TolstoyDotCom L.A.
The core patch from the other issue is the same as the merge request mentioned in my #10 and #14 comments.
In your site, does core/lib/Drupal/Component/Render/FormattableMarkup.php contain ctype_alnum?
- π©πͺGermany marcoka
Yes as i used your merge request.
https://git.drupalcode.org/issue/drupal-3173103/-/blob/3173103-false-pos... - First commit to issue fork.
- Status changed to Needs review
about 1 year ago 5:36pm 28 September 2023 - Open on Drupal.org βCore: 9.5.x + Environment: PHP 8.1 & MySQL 5.7last update
about 1 year ago Waiting for branch to pass - πΊπΈUnited States jrglasgow Idaho
Looking at this I see that this section in src/Plugin/views/field/ViewsConditionalField.php ViewsConditionalField->render()
// Translate text to be displayed with a context specific to this module, // view and display. $translation_context = "views_conditional:view:{$this->view->id()}"; // Translate prior to replacements, otherwise the dynamic replacement // content results in endless translations: if ($this->options['then_translate']) { $then = $this->t($then, ['context' => $translation_context]); } if ($this->options['or_translate']) { $or = $this->t($or, ['context' => $translation_context]); }
the calls to
$this->t()
have the $options array with the context key being passed in as the second argument, where is should be the third argument. - see StringTranslationTrait::t. This was cauaing the $options array to be treated as the $args array.attached is a patch that fixes this
- Open on Drupal.org βCore: 9.5.x + Environment: PHP 8.1 & MySQL 5.7last update
about 1 year ago Waiting for branch to pass - @jrglasgow opened merge request.
- Status changed to RTBC
about 1 year ago 2:59am 7 November 2023 - π¨π¦Canada joseph.olstad
Hitting this on another project now, it's time that this gets fixed.
- First commit to issue fork.
- Open on Drupal.org βCore: 9.5.x + Environment: PHP 8.1 & MySQL 5.7last update
about 1 year ago Waiting for branch to pass -
shelane β
committed 8a277ed7 on 8.x-1.x authored by
jrglasgow β
Issue #3347741 by jrglasgow, kferencz91: D10 "Invalid placeholder (...
-
shelane β
committed 8a277ed7 on 8.x-1.x authored by
jrglasgow β
- Status changed to Fixed
about 1 year ago 3:14pm 7 November 2023 - π¨π¦Canada joseph.olstad
Thanks very much @shelane! :)
It's even tagged in a release. Greatly appreciated!
https://www.drupal.org/project/views_conditional/releases/8.x-1.9 β
Automatically closed - issue fixed for 2 weeks with no activity.