Problem/Motivation
\Drupal::service('typed_data_manager')->createDataDefinition('entity:user')->getLabel(); helpfully returns the the label of the entity type, in this case user.
\Drupal::service('typed_data_manager')->createDataDefinition('field_item:string')->getLabel(); returns nothing.
It would be helpful if this returned the label of the field type. This can be used when working with configurable contexts to show what type of data a context is.
Steps to reproduce
Run \Drupal::service('typed_data_manager')->createDataDefinition('field_item:string')->getLabel(); get nothing returned
Proposed resolution
Add a getLabel() method to FieldItemDataDefinition that returns the label of the field type plugin.
Remaining tasks
Change record
User interface changes
NA
API changes
core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php has a new method getLabel().
Data model changes
NA
Release notes snippet
NA
| Comment | File | Size | Author |
|---|
Issue fork drupal-3128190
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:
- 3128190-fielditemdatadefinitiongetlabel-should-show
changes, plain diff MR !5550
Comments
Comment #2
rlmumfordComment #3
msutharsComment #4
msuthars@rlmumford Use
$this->getTypedDataManager()instead of$this->typedDataManager. Also can you write test case for it.Comment #6
sja112 commentedUpdated patch to add $this->getTypedDataManager() instead of $this->typedDataManager.
Please review.
Comment #7
msutharsNo need to add
TypedDataTraittrait, Parent class already using this triat. Updated the patch.Comment #13
smustgrave commentedgetLabel should be typehinted as a new function.
Also some test coverage will be needed
Thanks!
Comment #15
phthlaap commentedI've added a test for the getLabel method. I would appreciate your assistance in reviewing it.
Thank you.
Comment #16
smustgrave commented#13 I should of also tagged for a change record. Can be super simple.
Recommend turning patch to MR as patches are going away.
Comment #18
phthlaap commentedI have created a merge request. Could you please take a look and let me know if everything is in order?
Comment #19
smustgrave commentedWill add to my list to take a look!
Comment #20
smustgrave commentedRemoving tests tag as they have been added and can be seen in the test-only feature
Believe the last thing to do is draft a change record.
Updated issue summary too with the correct template
Comment #21
phthlaap commentedPlease help to review change record https://www.drupal.org/node/3404250
Comment #22
smustgrave commentedThanks! Think this one is good.
Comment #23
quietone commentedI'm triaging RTBC issues. I read the IS and the comments, the MR and the Change record.
Thanks for working on this feature!
Overall, the change is working but there is some more things to do to finish this.
Back to needs work for a few more things.
Comment #24
quietone commentedComment #26
prashant.cDONE
Comment #27
phthlaap commentedI resolved all items in comment #23. Please help to review.
Comment #28
smustgrave commentedFeedback appears to be addressed.
Comment #29
quietone commentedI left two suggestions in the MR to simply method name and a comment.
Comment #31
keshav patel commentedUpdated the method name and comment as per #29, Please review.
Comment #32
smustgrave commentedAppears suggestions were adopted
Comment #33
alexpottCommitted and pushed 94b03bcdec to 11.x and 973d283bea to 10.3.x. Thanks!
This is almost a bug...
We cannot add a return type here. This would break contrib code that extends this class and overrides the method already.
Fixed on commit.
Comment #36
alexpottAfter committing I wonder if we should push this fix to the parent class and make the following change...
And remove the override in FieldItemDataDefinition
Can someone file a follow-up to do this?
Comment #38
phthlaap commentedAs @alexpott suggestion, I moved code to parent class but I dont know how to fix the test failed.