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().

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.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

novchuk.v created an issue. See original summary.

novchuk.v’s picture

Assigned: novchuk.v » Unassigned
Status: Active » Needs review
StatusFileSize
new47.27 KB

Status: Needs review » Needs work

The last submitted patch, 2: replace-t-with-this-t-3188650.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

novchuk.v’s picture

StatusFileSize
new47.73 KB
novchuk.v’s picture

Status: Needs work » Needs review
StatusFileSize
new47.73 KB

Status: Needs review » Needs work

The last submitted patch, 5: replace-t-with-this-t-3188650-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

chaitanyadessai’s picture

Status: Needs work » Needs review
StatusFileSize
new62.06 KB
new208.58 KB

Please review patch.
Replaced t() with $this->t() in all plugins

Status: Needs review » Needs work

The last submitted patch, 7: 3188650-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

StatusFileSize
new2.05 KB

Providing updated patch. i think we only need to use StringTranslationTrait for classes which extends PluginBase.

nitin_lama’s picture

Status: Needs work » Needs review

Please review. Thanks.

nitin_lama’s picture

Assigned: nitin_lama » Unassigned
solideogloria’s picture

Status: Needs review » Needs work
Issue tags: +Novice

The patch should be converted to a merge request.

aryan singh’s picture

Working...

aryan singh’s picture

Status: Needs work » Needs review

liam morland made their first commit to this issue’s fork.

solideogloria’s picture

Status: Needs review » Needs work

There are definitely other classes that can use $this->t(). CronJobForm is one, since it extends EntityForm. I also think it should StringTranslationTrait could be used in CronJobDiscovery and other such classes. Any class using dependency injection should use it.

solideogloria’s picture

Status: Needs work » Needs review
solideogloria’s picture

solideogloria’s picture

Title: Replace t() with $this->t() in all plugins » Replace t() with $this->t() in all classes
solideogloria’s picture

berdir’s picture

Status: Needs review » Needs work

Conflicts with the short array syntax issue.

solideogloria’s picture

Status: Needs work » Needs review

Rebased

berdir’s picture

Status: Needs review » Needs work

reviewed.

solideogloria’s picture

Status: Needs work » Needs review

  • berdir committed 3d63d467 on 8.x-2.x authored by aryan singh
    feat: #3188650 Replace t() with $this->t() in all classes
    
    By:...
berdir’s picture

Status: Needs review » Fixed

Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

solideogloria’s picture

@berdir I'm not credited in the contribution record, for some reason, despite committing multiple times. Can you fix that, please?

berdir’s picture

I updated that.

solideogloria’s picture

Thanks.

Status: Fixed » Closed (fixed)

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