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
| Comment | File | Size | Author |
|---|
Issue fork ultimate_cron-3188650
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
Comment #2
novchuk.v commentedComment #4
novchuk.v commentedComment #5
novchuk.v commentedComment #7
chaitanyadessai commentedPlease review patch.
Replaced t() with $this->t() in all plugins
Comment #9
nitin_lamaComment #10
nitin_lamaProviding updated patch. i think we only need to use StringTranslationTrait for classes which extends PluginBase.
Comment #11
nitin_lamaPlease review. Thanks.
Comment #12
nitin_lamaComment #13
solideogloria commentedThe patch should be converted to a merge request.
Comment #14
aryan singh commentedWorking...
Comment #16
aryan singh commentedComment #18
solideogloria commentedThere are definitely other classes that can use
$this->t().CronJobFormis one, since it extendsEntityForm. I also think it shouldStringTranslationTraitcould be used inCronJobDiscoveryand other such classes. Any class using dependency injection should use it.Comment #19
solideogloria commentedComment #20
solideogloria commentedComment #21
solideogloria commentedComment #22
solideogloria commentedComment #23
solideogloria commentedComment #24
berdirConflicts with the short array syntax issue.
Comment #25
solideogloria commentedRebased
Comment #26
berdirreviewed.
Comment #27
solideogloria commentedComment #29
berdirMerged.
Comment #31
solideogloria commented@berdir I'm not credited in the contribution record, for some reason, despite committing multiple times. Can you fix that, please?
Comment #32
berdirI updated that.
Comment #33
solideogloria commentedThanks.