There's a bunch of label methods in EntityTypeInterface which should return a string but ConfigEntityType instances usually return a TranslatableMarkup instance.

This is the case for the following methods:

  • getLabel()
  • getCollectionLabel()
  • getSingularLabel()
  • getPluralLabel()
  • getCountLabel()
  • getGroupLabel()

Comments

geertvd created an issue. See original summary.

Version: 8.5.x-dev » 8.6.x-dev

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

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

This is a pretty frequent thing, to return markup. Let's update the docs.

mpp’s picture

Status: Active » Needs review
StatusFileSize
new5.04 KB
mpp’s picture

StatusFileSize
new4.31 KB
heddn’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -179,7 +179,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
-   * @var string
+   * @var \Drupal\Core\StringTranslation\TranslatableMarkup

I don't think they always return TranslatableMarkup. Sometimes it is a string. So we should type hint both in many of these places.

string|\Drupal\Core\StringTranslation\TranslatableMarkup

phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: +Novice, +API Documentation

+1 for what @heddn said. It needs to be "stringable", but not necessarily a primitive string. Kicking this back for that; also tagging as a novice issue since this issue is about copying-and-pasting a single change to many docblocks.

heddn’s picture

Also, based on #2990464: Breadcrumb markup should allow some tags such as italics or strong, anything renderable to a string. Which means sometimes render arrays (yikes!) and FormattableMarkup. So, anything castable to a string or renderable. Not sure how we handle these edges cases in a type hint. Or maybe we don't allow for render arrays in the hint so as to more better communicate we'd like to see string|FormattableMarkup... Which BTW, TranslatableMarkup is an implementation of FormattableMarkup, so maybe we want to hint on FormattableMarkup instead?

phenaproxima’s picture

FormattableMarkup is an instance of MarkupInterface, so we could in theory type hint to that. I have never seen any of those methods return a render array, so I don't think we need to go that far. string|TranslatableMarkupis probably fine, and would be my preference.

hardikpandya’s picture

Status: Needs work » Needs review
StatusFileSize
new4.88 KB
new4.39 KB
mpp’s picture

From a theoretical perspective, I'd argue that methods should accept interfaces so it should probably be MarkupInterface but string|TranslatableMarkup should be fine.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Okay, then I think we're good to go.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2728cbe and pushed to 8.7.x. Thanks!

  • catch committed 2728cbe on 8.7.x
    Issue #2921307 by mpp, hardikpandya, heddn, phenaproxima, geertvd: \...

Status: Fixed » Closed (fixed)

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