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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Status: Active » Needs review
Issue tags: +D8MI, +language-base
FileSize
3.07 KB

Here we go.

Status: Needs review » Needs work

The last submitted patch, 2: 2767025-2-entity-collection-label.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
813 bytes
3.07 KB

Someone 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.

Berdir’s picture

We'll end up with a million labels :)

See also #2507235: EntityType::getLowercaseLabel() breaks translation

tstoeckler’s picture

Yes, 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.

kristiaanvandeneynde’s picture

Patch 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

This could have perhaps been a 'labels' array in the annotation, much like we have 'handlers', 'links', etc.

This 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.

tstoeckler’s picture

Yes, I agree.

Anyone care to RTBC, then? :-)

kristiaanvandeneynde’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2813895: Combine entity type labels in an array

Go on then :)

timmillwood’s picture

I 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2767025-4-entity-collection-label.patch, failed testing.

timmillwood’s picture

Status: Needs work » Reviewed & tested by the community

moving back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2767025-4-entity-collection-label.patch, failed testing.

timmillwood’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2767025-4-entity-collection-label.patch, failed testing.

Sam152’s picture

Status: Needs work » Needs review
FileSize
698 bytes
3.75 KB

Given we didn't get a green test run, probably worth removing the @toddo and uploading the patch again.

kristiaanvandeneynde’s picture

Sometimes 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 :)

tstoeckler’s picture

Status: Needs review » Needs work

If we remove the to-do, we also need to fix it ;-), which means using EntityType::getCollectionLabel().

Sam152’s picture

Status: Needs work » Needs review
FileSize
746 bytes
3.87 KB

Good catch. Updated.

Status: Needs review » Needs work

The last submitted patch, 21: 2767025-21-entity-collection-label.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
1.99 KB
5.11 KB

Let's see if casting to string is enough. Also fixes the unit test for the changed behavior.

kristiaanvandeneynde’s picture

Status: Needs review » Needs work

- // @todo Improve this in https://www.drupal.org/node/2767025
- '_title' => '@label entities',
- '_title_arguments' => ['@label' => $entity_type->getLabel()],
+ '_title' => (string) $entity_type->getCollectionLabel(),

I 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?

Gábor Hojtsy’s picture

Issue tags: +sprint, +Workflow Initiative

I 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.

+++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php
@@ -628,6 +628,14 @@ public function getLabel();

@@ -628,6 +628,14 @@ public function getLabel();
   public function getLowercaseLabel();
 
   /**
+   * Gets the collection label of the entity type.
+   *
+   * @return string
+   *   The collection label.
+   */
+  public function getCollectionLabel();
+

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.

timmillwood’s picture

One could argue that all entity types should extend EntityType which implements the methods from EntityTypeInterface therefore this is not a backwards compatibility break. However we've already had comments when using the same argument for ContentEntityBase and ContentEntityInterface.

Gábor Hojtsy’s picture

Needs release manager review for the allowed changes.

I think only the changes suggested by @kristiaanvandeneynde would be outstanding otherwise.

tstoeckler’s picture

Here 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 typehints string as a return value, so that your IDE will complain about the getUntranslatedString() 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 include TranslatableMarkup.

That way this issue is minimal in scope and can hopefully go in soon!

tstoeckler’s picture

Status: Needs work » Needs review
Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -756,6 +763,17 @@ public function getLowercaseLabel() {
+      $this->label_collection = new TranslatableMarkup('@label entities', ['@label' => $label], [], $this->getStringTranslation());

+++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
@@ -320,9 +320,7 @@ protected function getCollectionRoute(EntityTypeInterface $entity_type) {
-          '_title_arguments' => ['@label' => $entity_type->getLabel()],
+          '_title' => $entity_type->getCollectionLabel()->getUntranslatedString(),
         ])

We 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 :)

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
2.93 KB
6.13 KB

Good 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.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good then. :) If a committer looks at this and believes release manager review is not needed they can still remove the tag and commit :)

xjm’s picture

Yeah, 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!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: 2767025-31.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community

CI error.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: 2767025-31.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
6.14 KB

Ahh, 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

kristiaanvandeneynde’s picture

Looks 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".

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This 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!

  • webchick committed c043032 on 8.3.x
    Issue #2767025 by tstoeckler, Sam152, kristiaanvandeneynde, timmillwood...
webchick’s picture

Issue tags: +8.3.0 release notes

Let's get a change record for this as well, please.

webchick’s picture

Issue tags: +Needs change record

  • webchick committed 402c4ea on 8.4.x
    Issue #2767025 by tstoeckler, Sam152, kristiaanvandeneynde, timmillwood...
xjm’s picture

Title: Add entity type label for a collection of entities » [Needs change record] Add entity type label for a collection of entities
Status: Fixed » Needs work
tstoeckler’s picture

Title: [Needs change record] Add entity type label for a collection of entities » Add entity type label for a collection of entities
Status: Needs work » Fixed
Issue tags: -Needs change record

Added a change notice, largely based on https://www.drupal.org/node/2689949

xjm’s picture

Thanks @tstoeckler!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

amateescu’s picture