Problem/Motivation

A long time ago I added (string) casts to those two methods, because they were some of the few examples of TranslationWrapper (how it was called back then) and it was used in some select opt groups.

Since we do that everywhere now, we can remove this.

This also removes 1 of the 3 (!!!) remaining actual translate calls* on the frontpage as uid. This happened in entity reference property definitions as part of an entity query.

* In case you're curious, the other two are "Site header" (aria label) and "Skip to main content". *Everything* else is cached or not displayed (which was caused by the t() change and that caused the number to go down from 14 to 3).

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
814 bytes
dawehner’s picture

Issue tags: +Needs tests, +Performance
+++ b/core/lib/Drupal/Core/Entity/EntityType.php
@@ -696,7 +696,7 @@ public function getDataTable() {
   public function getLabel() {
-    return (string) $this->label;
+    return $this->label;
   }
 
   /**
@@ -733,7 +733,7 @@ public function getGroup() {

@@ -733,7 +733,7 @@ public function getGroup() {
    * {@inheritdoc}
    */
   public function getGroupLabel() {
-    return !empty($this->group_label) ? (string) $this->group_label : $this->t('Other', array(), array('context' => 'Entity type group'));
+    return !empty($this->group_label) ? $this->group_label : $this->t('Other', array(), array('context' => 'Entity type group'));
   }
 

Let's ensure our test coverage has the additional logic on top of it.

Wim Leers’s picture

This also removes 1 of the 3 (!!!) remaining actual translate calls* on the frontpage

\o/

dawehner’s picture

Status: Needs review » Needs work

The last submitted patch, 2: entity-type-label-2575493-2.patch, failed testing.

Berdir’s picture

Fixing tests and making @dawehner happy ;)

dawehner’s picture

  1. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
    @@ -284,6 +286,44 @@ public function testId() {
    +  public function testgetLabel() {
    ...
    +  public function testgetGroupLabel() {
    

    Nitpick: testget -> testGet

  2. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
    @@ -284,6 +286,44 @@ public function testId() {
    +    $string_translation = $this->getMock(TranslationInterface::class);
    +    $string_translation->expects($this->atLeastOnce())
    +      ->method('translate')
    +      ->with('Other', array(), array('context' => 'Entity type group'))
    +      ->willReturn($default_label);
    

    I'd have used a SafeString object, but well, its a choice of everyone

Berdir’s picture

Fixed that get :)

2. is correct, we are testing the fallback t() call in that method, we can't decide what to return.

The last submitted patch, 7: entity-type-label-2575493-7-tests-only.patch, failed testing.

The last submitted patch, 2: entity-type-label-2575493-2.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

The last submitted patch, 7: entity-type-label-2575493-7-tests-only.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3e59ace and pushed to 8.0.x. Thanks!

Reducing the number of times things are translated is a key performance concern.

  • alexpott committed 3e59ace on 8.0.x
    Issue #2575493 by Berdir, dawehner: Remove string cast of EntityType::...

Status: Fixed » Closed (fixed)

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