Problem/Motivation

When attempting to unit test a widget which extends the StringTextfieldWidget the traditional method of mocking the string translation service fails and an error is produced Call to undefined function Drupal\Core\Field\Plugin\Field\FieldWidget\t().

On further inspection many of the plugins extending PluginBase do not utilize $this when calling t().

Proposed resolution

PluginBase is using StringTranslationTrait but many of the child plugins are not utilizing it properly. Use $this->t() instead of t() for string translation calls for all classes extending PluginBase.

CommentFileSizeAuthor
#2 3185843-2.patch6.73 KBmero.s

Comments

mero.S created an issue. See original summary.

mero.s’s picture

Assigned: mero.s » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.73 KB

Please, review patch

andrewsizz’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

  • jsacksick committed f77c248 on 8.x-2.x authored by mero.S
    Issue #3185843 by mero.S, AndrewsizZ: Replace t() by $this->t() in...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Status: Fixed » Closed (fixed)

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