Problem/Motivation

There are t() calls in Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::propertyDefinitions
which really don't have to run on every request, the label of a ER field which is not rendered by default.

Small optimization: ~0.2% of /node/1 as normal user with caching enabled.

Proposed resolution

Replace it with a translation wrapper.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

stefan.r’s picture

Status: Active » Needs review
StatusFileSize
new1.78 KB

yay .2% :)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I don't see why not, honestly :)

jibran’s picture

Nice I can also fix this in DER.

alexpott’s picture

Category: Task » Bug report
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
@@ -82,19 +83,19 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
-        ->setLabel(t('@label ID', array($target_type_info->getLabel())))
+        ->setLabel(new TranslationWrapper('@label ID', array($target_type_info->getLabel())))
...
-        ->setLabel(t('@label ID', array($target_type_info->getLabel())));
+        ->setLabel(new TranslationWrapper('@label ID', array($target_type_info->getLabel())));

There's no @label => $target_type_info->getLabel() here so this can't be tested atm

stefan.r’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.93 KB
new3.04 KB
borisson_’s picture

StatusFileSize
new1.19 KB
new3.92 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I really like how we get more tests everytime someone did an error.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Yep we should avoid unnecessary t(). Committed b8ac53f and pushed to 8.0.x. Thanks!

  • alexpott committed b8ac53f on 8.0.x
    Issue #2542292 by stefan.r, borisson_: Use TranslationWrapper instead of...

Status: Fixed » Closed (fixed)

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