Problem/Motivation
#1850080: Entity type labels lack plurality, cannot generate UI text based on label if plural is needed added various types of labels. However, an uppercase plural label, i.e. a label to use as the page title of an entity collection, was missed.
Proposed resolution
Add a getCollectionLabel()
method to EntityType(Interface)
that fetches a label_collection
. This is inline with #1850080: Entity type labels lack plurality, cannot generate UI text based on label if plural is needed and can be used to auto-generate a collection
route for entities in the future.
Remaining tasks
User interface changes
None.
API changes
A new getCollectionLabel()
method on EntityTypeInterface
. #1850080: Entity type labels lack plurality, cannot generate UI text based on label if plural is needed going into both 8.2 and 8.1 is proof that this is acceptable.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#37 | 2767025-37.patch | 6.14 KB | tstoeckler |
#18 | 2767025-18-entity-collection-label.patch | 3.75 KB | Sam152 |
#18 | interdiff.txt | 698 bytes | Sam152 |
#4 | 2767025-4-entity-collection-label.patch | 3.07 KB | tstoeckler |
|
Comments
Comment #2
tstoecklerHere we go.
Comment #4
tstoecklerSomeone seriously needs to slap me every time I write a unit test that I don't run locally. It's really a terrible thing to do. Sorry about that.
Comment #5
BerdirWe'll end up with a million labels :)
See also #2507235: EntityType::getLowercaseLabel() breaks translation
Comment #6
tstoecklerYes, I know :-) Not super happy about the current implementation, but with the parent issue having gone that way, I don't think there's much we can do.
Comment #7
kristiaanvandeneyndePatch looks good to me and makes sense given all the other labels we have in the annotation now. But yeah, I agree with Berdir in #5 too :/
This could have perhaps been a 'labels' array in the annotation, much like we have 'handlers', 'links', etc.
Comment #9
dawehnerThis sounds like a good idea in general, I think. On the other hand this doesn't really belong here. We could have its own issue to discuss this change and introduce the needed BC layers.
Comment #10
tstoecklerYes, I agree.
Anyone care to RTBC, then? :-)
Comment #11
kristiaanvandeneyndeGo on then :)
Comment #12
timmillwoodI guess this issue should really remove the
@todo
in DefaultHtmlRouteProvider::getCollectionRoute too.Hopefully this can be done at commit to save any of use rolling a new patch.
Comment #14
timmillwoodmoving back to RTBC
Comment #16
timmillwoodComment #18
Sam152 CreditAttribution: Sam152 commentedGiven we didn't get a green test run, probably worth removing the @toddo and uploading the patch again.
Comment #19
kristiaanvandeneyndeSometimes testbot seems to go crazy like that. It doesn't necessarily mean that it's this issue that broke it. I am curious as to the results of re-uploading the same patch, though :)
Comment #20
tstoecklerIf we remove the to-do, we also need to fix it ;-), which means using EntityType::getCollectionLabel().
Comment #21
Sam152 CreditAttribution: Sam152 commentedGood catch. Updated.
Comment #23
tstoecklerLet's see if casting to string is enough. Also fixes the unit test for the changed behavior.
Comment #24
kristiaanvandeneyndeI may be wrong but aren't route titles supposed to be untranslated? Because _title_arguments and _title_context is later on used to pass the whole thing to t() along with _title?
Comment #25
Gábor HojtsyI think getLabel() would return a TranslatableMarkup, so we can get the source string / any placeholders and merge them in to the route parameters? Otherwise it does seem like @kristiaanvandeneynde has a valid concern.
This interface is not marked internal. Are we allowed to change it (thus make anyone implementing it WSOD/fatal)?
Also tagging for workflow initative based on #2811407: "Workflow entities" admin page title should be "Workflows" and D8MI sprint.
Comment #26
timmillwoodOne could argue that all entity types should extend
EntityType
which implements the methods fromEntityTypeInterface
therefore this is not a backwards compatibility break. However we've already had comments when using the same argument forContentEntityBase
andContentEntityInterface
.Comment #27
Gábor HojtsyNeeds release manager review for the allowed changes.
I think only the changes suggested by @kristiaanvandeneynde would be outstanding otherwise.
Comment #28
tstoecklerHere we go.
Thanks @kristiaanvandeneynde for raising this. Really, really nice (and impressive!) catch! You are absolutely correct. I looked through core and found a couple other cases where we are now double-translating route titles due to this, will open a follow-up.
Also note that the
getCollectionLabel()
method typehintsstring
as a return value, so that your IDE will complain about thegetUntranslatedString()
method. This is for consistency with all the other labels. I will open another follow-up to adapt the return type-hint for all the label methods to includeTranslatableMarkup
.That way this issue is minimal in scope and can hopefully go in soon!
Comment #29
tstoecklerComment #30
Gábor HojtsyWe should also bring over title arguments from the method's return value as demonstrated by the default implementation, otherwise we'll end up with "@label entities" without the placeholder value :)
Comment #31
tstoecklerGood point. Also bringing over the context, then, for completeness.
Regarding the needed release manager review, this is very much in line with #1850080: Entity type labels lack plurality, cannot generate UI text based on label if plural is needed which was also commited to 8.3.x which is why I didn't tag it with myself. Doesn't hurt I guess, though, to confirm that this is fine.
Comment #32
Gábor HojtsyLooks good then. :) If a committer looks at this and believes release manager review is not needed they can still remove the tag and commit :)
Comment #33
xjmYeah, this looks like a sensible and normal API addition for a minor release, and 8.3.x is still open, so no release management review needed. Leaving RTBC since I haven't reviewed this in depth. Thanks!
Comment #35
tstoecklerCI error.
Comment #37
tstoecklerAhh, this conflicted with #2194783: Rename EntityTypeInterface::isSubclassOf() to ::entityClassImplements(). Git was able to resolve the merge, though, so I will comfortable re-RTBCing per #32, as the patch really is unchanged.
Edit: Fix issue link
Comment #38
kristiaanvandeneyndeLooks great!
Re #28: I found out about it when writing my own permission handler that core tends to work with untranslated strings for almost anything that can go into a YAML file. It's only translated once "loaded".
Comment #40
webchickThis is definitely vastly preferable to the amount of backflips and somersaults needed to do something as simple as #2811407: "Workflow entities" admin page title should be "Workflows" right now. I see @Berdir is a bit lukewarm to the idea, but it seems like a minimally invasive approach for now, which doesn't make the existing situation much worse, and allows us to explore something along the lines of #9 for 8.4.x.
Committed and pushed to 8.4.x and cherry-picked to 8.3.x. Thanks!
Comment #42
webchickLet's get a change record for this as well, please.
Comment #43
webchickComment #45
xjmComment #46
tstoecklerAdded a change notice, largely based on https://www.drupal.org/node/2689949
Comment #47
xjmThanks @tstoeckler!
Comment #49
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI opened #2869039: Group all entity labels under a single 'labels' annotation key for implementing the suggestion in #7.