Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The !variable place holder for the proper formatting of strings is no longer valid as per !placeholder removed from t() and format_string(), and is causing errors. To further illustrate, it has been removed from the documentation.
This is an example of a produced error:
User error: Invalid placeholder (!count) in string: !amount every !count months in Drupal\Component\Render\FormattableMarkup::placeholderFormat() (line 233 of core/lib/Drupal/Component/Render/FormattableMarkup.php).
Here's how to find all of the instances:
colan@snake[Mon 13 12:48]% grep -rn "'\!" .
./src/Form/RecurlyRedeemCouponForm.php:194: '!coupon' => $this->recurlyFormatter->formatCoupon($coupon, $form_state->getValue(['coupon_currency'])),
./src/RecurlyEntityOperations.php:106: '!title' => \Drupal::l($entity->label(), $entity->toUrl()),
./src/RecurlyFormatManager.php:139: '!count' => $html ? '<span class="plan-count">' . SafeMarkup::checkPlain($count) . '<span>' : SafeMarkup::checkPlain($count),
./src/RecurlyFormatManager.php:140: '!amount' => $html ? '<span class="plan-amount">' . $amount . '</span>' : $amount,
./src/RecurlyFormatManager.php:145: return t('!amount per day', $replacements);
./src/RecurlyFormatManager.php:148: return t('!amount per month', $replacements);
./src/RecurlyFormatManager.php:152: return t('!amount per week', $replacements);
./src/RecurlyFormatManager.php:155: return t('!amount per year', $replacements);
./src/RecurlyFormatManager.php:160: return t('!amount every !count days', $replacements);
./src/RecurlyFormatManager.php:163: return t('!amount every !count months', $replacements);
Comment | File | Size | Author |
---|---|---|---|
#11 | variable_placeholder-2747935-11.patch | 6.4 KB | adamzimmermann |
#6 | interdiff-2747935-5-6.txt | 1.97 KB | colan |
#6 | recurly-replace_bang_variable_placeholders-2747935-6.patch | 6.25 KB | colan |
#5 | recurly-replace_bang_variable_placeholders-2747935-5.patch | 5.67 KB | colan |
#5 | interdiff-2747935-3-5.txt | 2.01 KB | colan |
Comments
Comment #2
markdorisonComment #3
colanI got all of the RecurlyFormatManager bits working and tested with this patch, but some additional testing is needed for the first two instances. I'm not that far along in my set-up to test these.
Comment #4
colanThe preformatted currency amounts are showing up with HTML tags as t() is escaping them. Working on including a fix...
Comment #5
colanHere's another patch, but I'm not crazy about this solution. Because the formatter methods are adding their own markup (span tags) and there's no longer a natural means by which to render unsanitized text, the fix here is doing the following:
I think we need to refactor how we're formatting currency amounts and price intervals (formatCurrency() and formatPriceInterval() respectively) to avoid doing this sort of thing. I'm not much of a themer, but here are some options (please add/edit/etc.):
If someone else who's front-end inclined could take a look into this, I'd really appreciate it.
Comment #6
colanAdded some missing fixes for various interval formats.
Comment #7
aburke626This patch looks solid to me - and I agree that a refactoring would be a good idea. Do you mind creating a new issue(s) for that as a starting point, and we can try to get some front-enders on it?
Comment #8
colan@aburke626: Thanks for looking into this.
How about simply taking over this issue? Feel free to rename it and/or change / add to the description.
I'm not expecting that we commit my patch above so I'm not sure we need separate issues. In other words, if this ticket is staying open, let's use it.
Comment #9
colanComment #10
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedI have a patch nearly complete for this that integrates with a template as suggested above. I want to do some additional testing next week, then I'll post it.
Comment #11
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedThis removes all
!
placeholders, and retains existing functionality to the best of my knowledge.I did pass
FALSE
toformatCoupon
inRecurlyRedeemCouponForm.php
to avoid dealing with HTML in thet()
function there. I don't think losing that price markup is too big of a deal though.Comment #13
adamzimmermann CreditAttribution: adamzimmermann at Chromatic commentedComment #14
markdorison