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.
Problem/Motivation
We don't need PlaceholderTrait, it's confusingly named considering we also have PlaceholderGenerator and it will only be used in value objects extending FormattableString
Proposed resolution
Make TranslatableString extend FormattableString and move PlaceholderTrait's methods back to FormattableString
Remaining tasks
Review patch
Commit
User interface changes
N/A
API changes
Removal of PlaceholderTrait, which was rushed in a week ago and never was mentioned in a CR
This unblocks #2576533: Rename SafeStringInterface to MarkupInterface and move related classes
Comment | File | Size | Author |
---|---|---|---|
#32 | 2577785-31.patch | 25.55 KB | alexpott |
#32 | 26-31-interdiff.txt | 5.94 KB | alexpott |
#29 | 2577785-21.patch | 25.23 KB | alexpott |
#26 | 2577785-25.patch | 24.83 KB | alexpott |
#26 | 21-25-interdiff.txt | 710 bytes | alexpott |
Comments
Comment #2
stefan.r CreditAttribution: stefan.r commentedGiven people really don't seem to like it in #2576533: Rename SafeStringInterface to MarkupInterface and move related classes (and it's blocking the issue), maybe we could just get rid of it instead? PlaceholderTrait would realistically only be used in TranslatableString and FormattableString
Comment #3
stefan.r CreditAttribution: stefan.r commentedComment #5
Wim Leers+1 for this direction, much clearer. I think it's clear this does more than pure documentation though, so adjusting the title accordingly.
So we keep this, but make it an empty shell?
This makes a ton of sense to me.
Comment #6
stefan.r CreditAttribution: stefan.r commentedYes, some didn't like us making a trait out of something with just a static method in #2557113: Make t() return a TranslationWrapper object to remove reliance on a static, unpredictable safe list anyway.
This wasn't turned into a trait because others might want to use it (they can just call FormattableString::format() or extend FormattableString if they want their own string value object), I think the worry was putting too much logic into a class defining a value object. Let me check with @dawehner as I think he came up with the idea.
Comment #7
stefan.r CreditAttribution: stefan.r commentedRe #5.1 I had just cut & pasted the code and forgot to remove the PlaceholderTrait file :)
Comment #8
dawehnerSo we keep an empty placeholder trait?
This is the question, is a translatable string semantically similar to a formatable string or are they more of a sibling or even something completely different? Inheritence for the sake of code sharing is always a bad sign, if you ask me.
Comment #9
dawehnerOn the other hand I can see how they are parent/child, especially if you look at the signature which is used at the end of the day.
Comment #10
stefan.r CreditAttribution: stefan.r commentedIMO a translatable string is exactly the same as a formattable string (markup), except it's also translatable
Comment #11
dawehnerYeah I think I agree now.
Adapted the title to not require people to look it up in a dictionary.
Comment #12
alexpott+1 to this. Makes a tonne of sense.
Let's remove PlaceholderTrait completely.
Comment #14
stefan.r CreditAttribution: stefan.r commentedComment #15
Wim Leers+1 to this direction.
Comment #16
xjmYeah this direction makes way more sense, +1.
Comment #17
stefan.r CreditAttribution: stefan.r commentedComment #19
alexpottI don't think we should be adding this functionality to FormattableString in this issue - it is completely unrelated.
Comment #20
xjmComment #21
alexpottRemoving ToStringTrait
Comment #22
Wim LeersThis is ready now. Let's get this in, that will unblock #2576533: Rename SafeStringInterface to MarkupInterface and move related classes.
Comment #23
dawehnerThese has been all usages of the word "PlaceholderTrait" in core.
Does someone mind opening up a new follow up to move the test coverage away from
\Drupal\Tests\Component\Utility\SafeMarkupTest::testFormat
?Comment #24
xjmThis doesn't seem in scope.
Comment #25
stefan.r CreditAttribution: stefan.r commentedwe inherit that from the parent
Comment #26
alexpottFixing #24.
Comment #27
alexpott#25 is correct - to me either #26 or #21 is committable and it really does not matter much which one. #21 has less unnecessary code.
Comment #28
Wim Leers#21 therefore was correct.
Comment #29
alexpottAnd given that this issue makes
TranslatableString
extendFormattableString
I think it is in scope to remove methods that are 100% the same. Re-uploading #21. Sorry for the disruption.Comment #30
xjm@alexpott and I discussed this--it's kinda borderline scope, but we need to fix it in other places too to make it consistent, so let's do that in a followup.
This is almost the same as, but not the same as, the class's one-line summary.
Not a trait anymore. :)
Some of this stuff is now duplicated between the class and method documentation. (In the previous issue, #2570431: Document that certain (non-"href") attribute values in t() and SafeMarkup::format() are not supported and may be insecure, we had to split it up and do some duplication because it was in two places. Another reason this change just makes more sense.)
Based on this hunk being in scope (which also makes sense), @alexpott and I discussed the other class members and determined that
$arguments
also does not need to be duplicated. The rest made sense to "override" the docs, or were not members of FormattableString.Comment #31
Wim LeersHaha, I was re-uploading #21 also in #28, but then cross-posted with #27, which made me decide it was probably better to not re-upload :P
Comment #32
alexpott1. fixed
2. I think this is okay... it is what the method does. However I do think
Replaces placeholders in a string with values.
is clearer and this makes me consider the nameplaceholderFormat
might be bad. MaybereplacePlaceholders()
is better since it is more descriptive. Will open a followup for this.3. Fixed and moved this documentation to the class level
4. See 3
5. Fixed.
Comment #33
xjm@alexpott also filed #2578377: Make translatable docs consolidated and better for developers.
Comment #34
Wim LeersComment #35
xjmThence no need for a change record. ;)
I reviewed this in dreditor, with
git diff --color-words
, and by comparing the moved lines, plus read the updated classes in toto.An "as" got rewrapped... can be fixed on commit.
Not introduced here but this hunk is a bad example for two reasons ($variable in the first parameter is bad for t() parsing, and that's going to inherit these docs. Note to self: followup.
Still needs a followup to rename the method and the parameter.
This "see" makes no sense now. Can be removed on commit.
Caught this with a
git diff --color-words
-- we are losing a colon here. Can also be fixed on commit.So this was weird... I double-checked and this was not used within the class itself, plus if any unit test ever used one of the methods on it, obviously that test would fail now. So this is fine.
Commit diff:
Thanks!
Comment #42
alexpottComment #43
YesCT CreditAttribution: YesCT commented#2580505: Improve FormattableMarkup documentation will do some of the follow-ups @xjm asked for.
I'm going to go through the comment thoroughly, and see if any additional ones are needing, or if more should be done in that issue to address all the concerns.
Comment #44
YesCT CreditAttribution: YesCT commentedI made #2580525: Rename placeholderFormat() to replacePlaceholders() and the argument args to arguments for #35 3.
I think that combined with #2580505: Improve FormattableMarkup documentation will address all the concerns. removing needs followup tag.