Problem/Motivation
Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
API changes
EntityDisplayInterface has been adjusted with the following methods added:
getTargetEntityTypeId();
getMode();
getOriginalMode();
getDisplayBundle();
setDisplayBundle($bundle);
As a result all the internal implementation in EntityDisplayBase has been made protected (all the previously public methods accessed by those new functions).
Any code currently in Drupal Core that touched these public variables has been updated to use the new methods.
Original report by @plopesc
Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
See the detailed explanations there and look at the issues that already have patches or were commited.
Add get*, set* and additional methods as it makes sense to replace the public properties (e.g. isSomething() and something())
Comment | File | Size | Author |
---|---|---|---|
#93 | interdiff.txt | 2.88 KB | Mile23 |
#93 | 2030607_93.patch | 26.69 KB | Mile23 |
#90 | interdiff.txt | 15.67 KB | Mile23 |
#90 | 2030607_90.patch | 26.7 KB | Mile23 |
#85 | interdiff.txt | 9.35 KB | amateescu |
Comments
Comment #1
marvin_B8 CreditAttribution: marvin_B8 commentedThere are no properties on this class, so I think we can close this issue.
Comment #2
BerdirThere are no properties on that, but there are properties on the EntityDisplayBase class, those should have methods that are defined on EntityDisplayBaseInterface.
Comment #3
joelpittet.
Comment #4
KingdutchWorking during mentored sprint : )
Comment #5
KingdutchI believe I got all the public methods, I left the protected methods alone.
Maybe for a follow-up issue: the setOriginalMethod feels a bit weird being public, the name suggests it's set at creation, never to be changed. The only problem at this moment is that the createCopy method would break when the setOriginalMethod is changed to protected.
Comment #7
KingdutchA bit too quick with the unassignment. Got some local feedback that EntityDisplay quickly got a new public property $status while I was working on this issue so I had to update it. Also added the forgotten @param doccomments for the setters.
Comment #9
KingdutchHad a misunderstanding with Drupal's "magic" get/set methods.
Comment #10
KingdutchForgot to set the status =|
Comment #12
Kingdutch#9: expand-entitydisplay-with-methods-2030607-9.patch queued for re-testing.
Comment #14
balagan CreditAttribution: balagan commentedJust saw you are using getTargetEntityType().
EntityDisplayModeBase has getTargetType() to return $this->targetEntityType.
Shouldn't the naming convention be consequent through all classes?
Comment #15
balagan CreditAttribution: balagan commentedJust renamed the issue title to include EntityDisplayBase instead of EntityDisplay
Comment #16
balagan CreditAttribution: balagan commentedI noticed that some of fago's comments to an issue I am working on also apply here. Check points 5. and 6 in the list of the linked comment.
Comment #17
balagan CreditAttribution: balagan commentedComment #18
balagan CreditAttribution: balagan commentedOk, so many things have changed, even one file used in previous patch is gone, so I start from the beginning:
I think the following properties need getters and setters:
The Meta issue says: Protected properties can be listed in the sub-issues, and considered case by case if a getter makes sense. Somebody please help with these, I have no idea.
I think ConfigEntityBase::$langcode should not be touched here.
Comment #19
balagan CreditAttribution: balagan commentedUploading patch with getters and setters for the public properties.
Comment #20
balagan CreditAttribution: balagan commentedComment #22
balagan CreditAttribution: balagan commentedAdded back status and id properties, and fixed gettargetTypeId() to getTargetTypeId()
Comment #23
balagan CreditAttribution: balagan commentedComment #24
Xano22: expand-entitydisplay-with-methods-2030607-22.patch queued for re-testing.
Comment #26
XanoRe-roll. I didn't have time to add tests, but that does need to be done before this issue can be RTBC'ed.
Comment #27
alexpottRerolled for PSR-4 and made properties protected to prove we're using the new methods everywhere we should. The interdiff is post PSR-4 reroll.
Comment #29
alexpottFixed test fails and added tests for the new methods. Also revert change to remove $status property since the docs are valuable.
Comment #32
mon_franco CreditAttribution: mon_franco commentedI have been reviweing this issue with @tstoeckler. A re-roll patch is updated.
Comment #33
mon_franco CreditAttribution: mon_franco commentedComment #35
Kingdutch$display->targetEntityType
was missed here. This should be$display->getTargetEntityTypeId()
like the first instance.Furthermore in the EntityDisplayBaseTest.php the namespace for EntityDisplayBase, which is in \Drupal\Core\Entity should probably be used. I'm not sure if this should be done using a 'use' statement or if this is caused because the path in getMockForAbstractClass is given \Drupal\entity\EntityDisplayBase as path whereas EntityDisplayBase is at \Drupal\Core\Entity\EntityDisplayBase.
Comment #36
KingdutchI can't run the updated test EntityDisplayBaseTest locally so I'm hoping they'll just pass on qa.d.o. EntityDisplayTest is now green. Changes are as per #35. In addition EntityDisplayBaseTest::getInfo has been removed as it is no longer used. (This suspicion was confirmed by Xano).
Comment #37
KingdutchAs always I forget the status : |
Comment #38
mradcliffeThe patch makes sense. The tests make sense too. I think we need a change record now that we're in beta because we technically are breaking the API for public -> protected object variables.
Xano mentions this as RTBC.
This is more of a comment about this code. Do we have the entity manager injected into this class? Might not be a big difference, but could be a follow-up issue.
We would probably need a change record for changing APIs at this point since we're in beta.
Could also use some injection love in a follow-up issue as well.
Comment #39
XanoWhat did I do?
Comment #40
XanoCan someone please update the issue summary with a section that describes the API changes? In this case you have to explain that the properties will no longer be public.
After that is done, the core maintainers can look at this and decide if it will get in or not.
Comment #41
XanoComment #42
KingdutchUpdated the issue summary. Leaving this to needs work as there was an @todo added to the patch, however the issue it points to has seemed to be resolved since. I'll assign this to myself and make a new patch to reflect this change.
Comment #43
tstoecklerSince this issue has been a long time coming, I would suggest to leave the change from public to protected of the variables (i.e. the actual API change) out of this for now and just add a @todo for now. Then we can tackle that in a smaller-scoped follow-up issue.
Comment #44
cilefen CreditAttribution: cilefen commentedRe-rolled because of #2275659: Separate FieldableEntityInterface out of ContentEntityInterface.
Comment #45
Mile23Re-roll of #44. The only conflict I had to resolve was changing line 92 of EntityDisplayTest.php to look like this:
$this->assertEqual(array('config' => ...
Comment #46
tstoecklerSorry, but I do not understand why we use getTargetEntityTypeId but getDisplayBundle. Shouldn't it be getTargetBundle?
Comment #47
balagan CreditAttribution: balagan commentedI guess Kingdutch forgot to unassign, so unassigning...
Comment #48
daffie CreditAttribution: daffie commentedThe patch looks good to me. All the class variabls are protected and functions are added to set and get them. There are also PHPUnit tests added to test the functions. I have two nitpicks that I would like to be solved before a RTBC.
In the doc blocks with the set functions the return value is set as this. Can we replace that? (see below)
In the doc block is a reference to #2286681: Make public properties on ConfigEntityBase protected. This issue is fixed a long time ago. so can we remove this?
Comment #49
Mile23@return $this
is valid docblock markup: https://www.drupal.org/coding-standards/docs#types It's different from returning any arbitrary EntityDisplayInterface.@todo
gone.Comment #50
daffie CreditAttribution: daffie commented@Mile23: You are right. I have read it in the coding-standards. My mistake.
After green from test-server, I shall give it RTBC.
Comment #51
daffie CreditAttribution: daffie commentedAll the class variables are now protected.
The new getter and setter functions are in order and included in the correct interface.
Also the comments are in order.
There are PHPUnit test added.
The test-server gives it a green light.
So for me it is a RTBC.
Comment #52
alexpottThis is inconsistent... if we're going to use a getter for one - why not all? It is okay for a class to know about it's own internals so i'd be fine with not doing this.
As above... all this change feels a bit unnecessary.
These setters have no usages and I don' think it should be changeable.
There are no usages of this... and setting this feels like an internal detail.
Comment #53
Mile23@alexpott: There was some question about
set()
in another similar issue. It has side-effects of using the plugin system. Whether or not we need those side effects is undocumented.Comment #54
rpayanmComment #55
Mile23Patch does not apply.
Comment #56
rpayanmComment #57
Mile23Straight-up reroll of #49. Will address issues in #52 when the testbot comes back.
Comment #58
daffie CreditAttribution: daffie commentedComment #59
hussainwebI am applying changes as per #52. It is basically removing various method calls in EntityDisplayBase.php.
Comment #61
hussainwebFixing the error.
Comment #63
hussainwebRemoving the removed methods from the test case.
Comment #64
daffie CreditAttribution: daffie commentedNitpick: The first line is too long. Can we move the word "modes" to the next line.
This line is not necessary.
Can we rewrite this to:
The same for the other methods.
Comment #65
daffie CreditAttribution: daffie commentedComment #66
adci_contributor CreditAttribution: adci_contributor commentedI think, we can't just move the "modes" to the next line, cuz all functions/methods need to start with a one-line description (https://www.drupal.org/node/1354#functions). So I've tried to split it correctly.
About #64:3 and testGetDisplayBundle(). Should we rewrite it too, or we need to replace
$this->set('bundle', $bundle);
in setDisplayBundle() ?Comment #67
daffie CreditAttribution: daffie commentedLooks good almost there.
Nitpick: You can remove the first line. You can remove the closing bracket from the second line.
For the setDisplayBundle() you do the following:
You can combine the tests for getDisplayBundle() and setDisplayBundle() into one test.
Comment #68
hussainwebChanging as per #67 with a small change. For the comment on getOriginalMode(), I used the first line as I thought that makes more sense. The second line did not make much sense to me:
Comment #69
daffie CreditAttribution: daffie commentedLooks good. Almost RTBC. One problem left.
You can remove this line. We are testing if the method setDisplayBundle() is working as it should. Now you overwrite the bundle property.
Comment #70
hussainwebChanged, and a little bit more but I think/hope that shouldn't matter.
Comment #71
daffie CreditAttribution: daffie commentedIt all looks good to me.
There class variables are now protected and the five methods from the issue summery are added to the class.
The documentation is in order.
It gets a RTBC from me.
Comment #74
daffie CreditAttribution: daffie commentedAnd back to RTBC.
Comment #75
yched CreditAttribution: yched commentedSorry, a couple additional nitpicks :
Slightly inaccurate - should be "for which this display is used".
Missing description
Not sure about that method name. The other methods don't have "Display".
This goes hand in hand with getTargetEntityTypeId(), so maybe getTargetBundle() / setTargetBundle() to keep consistency ?
Plus, FieldDefinitionInterface has getTargetEntityTypeId() / getTargetBundle() for something that its conceptually the same - the entity type and bundle this "thing" (display, field...) is about.
No reason for this. We are in the class, we can still access a protected property - and we do throughout the rest of the class, including in that very line.
So, for consistency, let's keep the property here.
Also, minor remark while we're in there: since they are basic getters and setters about the basic properties of the object, the new methods would be better off at the top of the interface, rather than added after the more advanced methods.
[edit: and same for the implementations in EntityDisplayBase]
Comment #76
hussainwebStarting with a reroll. Will revert to Needs Work for review points after this patch passes.
For the record, I will also remove calls to set() method in specific setters as per #2030633-153: Expand FieldStorageConfig with methods point 5.
Comment #77
hussainwebComment #78
hussainwebIt seems I had to reroll before I could get to the changes. Same as #76.
Comment #82
hussainwebWho would think it would need a reroll so soon. What I said in #76 still applies.
Comment #84
hussainwebI am hoping this fixes most (or all) of the errors.
Comment #85
amateescu CreditAttribution: amateescu commentedThis will get you even farther :) I'm just updating all the new calls introduced in #2094499: Convert "Manage (form) display" forms to be the official entity edit forms for EntityView[Form]Display objects.
Comment #87
daffie CreditAttribution: daffie commentedIt all looks good to me.
There class variables are now protected and the five methods from the issue summery are added to the class.
The documentation is in order.
It gets a RTBC from me.
Comment #88
yched CreditAttribution: yched commentedThe remarks in #75 haven't been adressed yet.
Comment #89
Mile23Comment #90
Mile23Thanks for the review, @yched.
Hopefully deals with #74.1-4.
For the minor nitpick part: There isn't a coding standard about that, and we always tell everyone to localize your changes so the patch is easy to review.
The whole point of an interface is that you don't know or care how complex the implementation is, so there's no way to evaluate which is simple or complex. I've left it alone, because it's roughly alphabetical, with get and set together.
I've arranged the base class in the way I'd like to encounter it, which I hope is good.
Comment #92
yched CreditAttribution: yched commentedThanks @Mile23.
Method order : not a blocker, but I'd still prefer to move the methods up in the interface. They are introduced here, so it doesn't make the patch easier or harder to review, and having a similar order in the interface and in implementations is easier when navigating between the two.
Was about to RTBC, but looks the bot doesn't agree :-)
Comment #93
Mile23Catching the refactoring that NetBeans didn't.
Comment #94
yched CreditAttribution: yched commentedTemptative RTBC if green
Comment #95
Mile23Ossum. :-)
Comment #96
alexpottI rerolled this patch for PSR-4 so I think it is fine for me to commit. Committed 2e92d42 and pushed to 8.0.x. Thanks!
The beta evaluation is in the meta issue.