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 |
|---|---|---|---|
| #72 | drupal8-expand-contact-form-methods-2030591-72.patch | 9.91 KB | jibran |
| #72 | interdiff.txt | 1.36 KB | jibran |
| #69 | drupal8-expand-contact-form-methods-2030591-69.patch | 10.2 KB | jibran |
| #66 | drupal8-expand-contact-form-methods-2030591-66.patch | 10.3 KB | l0ke |
| #64 | drupal8-expand-category-methods-2030591-64.patch | 17.03 KB | martin107 |
Comments
Comment #1
kgoel commentedGoing to work on this.
Comment #2
yesct commented@kgoel Did you have any questions or intermediate work to post?
Comment #3
kgoel commented@YesCT I am going to look at other similar patches and work on this today.
Comment #4
kgoel commentedWorking on this now.
Comment #5
kgoel commentedComment #7
ivan zugec commented#5: expand-category-methods-2030591-5.patch queued for re-testing.
Comment #9
kgoel commentedI have tried running test locally to see if patch passes but I ran into some error while running test - Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "The service "access_check.contact_personal" has a dependency on a non-existent service "user.data"."
I googled the error and found the other issue is also running into the same error https://drupal.org/node/1938390 and looks like this issue depend on https://drupal.org/node/2048223.
Comment #10
daffie commented@kgoel: The two issues you are referring to are fixed #1938390: Convert contact_site_page and contact_person_page to a new-style Controller and #2048223: Add $account argument to AccessCheckInterface::access() method and use the current_user service.
Comment #11
kgoel commentedThanks Daffie!
Comment #12
kgoel commentedComment #13
kgoel commentedComment #16
daffie commented12: expand-category-methods-2030591-11.patch queued for re-testing.
Comment #18
sharique commentedHere is updated patch, it still need some work.
Comment #19
sharique commentedForgot to change the status.
Comment #20
sharique commentedAdded wrong patch, adding correct patch.
Comment #21
piyuesh23 commented@sharique, your patch is not able to set the properties like label/recipients/weight/reply for the contact form categories.
Uploading another patch with this fixed.
Comment #23
piyuesh23 commentedAdding back the test class from patch in comment#11.
Comment #25
sharique commentedAdded missing test file provided by kgoel, to last patch.
Comment #26
sharique commentedWhen I run tests for CategoryMethodsTest it gives following error, can somebody help me understand this error.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "access_check.contact_personal" has a dependency on a non-existent service "user.data". in Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processReferences() (line 59 of /home/sharique/Projects/drupal.org/d8/drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php).
Comment #27
martin107 commentedLooking at CategoryMethodsTest I see nothing defines $this->category
I think you needed an entity_create() before you start asserting things
Comment #28
sharique commentedUpdated patch. Fixed failing tests.
Comment #29
pcambraRe roll as CategoryListController is now CategoryListBuilder
Comment #30
andypostany reason to drop default values?
makes sense as unittest
Comment #31
daffie commentedShould the function setLabel be:
Instead of:
Comment #32
tim-e commentedComment #33
martin107 commentedJust a reroll...
Comment #34
martin107 commentedComment #35
tim-e commentedBit of a nitpick, sorry but got a typo here.
Missing full stop?
As andypost pointed out, any reason to remove the defaults?
Just a couple minor things.
Comment #36
tim-e commentedoh also +1 for andypost's comment #30 - "makes sense as unittest"
Comment #37
pushpinderchauhan commentedDid minor correction mention in #35 and #36. Please review updated patch.
Comment #39
martin107 commentedJust a mini review
This patch introduces a new test CategoryMethodsTest and the getInfo() function has been removed from core.
#697760: Replace getInfo() in tests with native phpDoc + annotations (following PHPUnit)
There is no drama the group information needs to be moved into annotations :-
I will just include the following snippet, for when the patch is back in a healthy state.
Comment #40
l0keReroll.
Comment #44
martin107 commentedSummary of test failure, problems resolving user.data, a perfectly well defined service.
Solution: CategoryMethodsTest was not enabling the user module, so could not find the service.
Comment #45
andypost@martin107 There's no reason to call
save()to make sure that set/get worksLet's see if we can make the properties protected to make sure they are not accessed directly
Converted test to unit-test, cleaned-up doc-blocks
Comment #47
martin107 commentedFixed up a few things.
Comment #48
andypostAwesome, +1 to rtbc!
@berdir anything left here?
Comment #49
berdirLooks fine to me.
Comment #50
alexpottIs this really needed - we have a label() method already?
These setter's are never used (outside of a test added by this patch) - should we really be adding them?
Comment #51
daffie commented@alexpott: Because core does not use the setter functions does not mean that contrib will not use them either. Unless you have a good argument why contrib not not use them.
Comment #52
larowlan+1 to use label() over getLabel()
Happy to keep the setters - no harm in having them, might save a contrib module using reflection :)
Comment #53
temoor commentedRemoved getLabel() and replaced it with label()
Comment #54
temoor commentedTriggering tests
Comment #56
larowlannote #2285083: Rename contact category to contact form is rtbc which will require a major re-roll here
Comment #57
m1r1k commentedComment #58
berdirComment #59
martin107 commentedReroll, from last good (#47)
using label() not getLabel()
review from #50 still needs addressing.
Comment #61
martin107 commentedFixed up one of the unit tests.
Other errors persist.
Comment #63
martin107 commentedFixed up errors common to many tests.
Comment #64
martin107 commentedSo a summary of the work needed from #50 combined with this quote from #52
That boils down to just remove the set/getLabel stuff.
So snip snip, the patch is smaller, there is no outstanding work to be done on this issue.
Comment #65
andypostPatch mostly wrong because does not take changes from commited #2285083: Rename contact category to contact form
Also about label there's #2199917: Implement EntityLabeledInterface
There's ContactFormEditForm now
Here's ContactFormInterface to extend and ContactForm entity
Comment #66
l0keJust a reroll, that removes CategoryForm and CategoryInterface.
Also not sure if we should add setters, in most issues from this META @alexpott asked to remove setters unused in core. I left setters for now, but for consistency setters have to be removed here also?
Comment #69
jibranFix the whitespace issue and just a simple reroll. I think the additional setters are fine here. This is ready to go so RTBC.
Comment #70
jibran#2325801: Abstract contact module mail delivery out of form into a service is postpone on this.
Comment #71
webchickI also don't have a problem with the setters specific to Contact module's stuff (and looking at a few others such as Menu.php and NodeType.php we seem to do this elsewhere), but setLabel() is problematic because it's a property that's found on all entities, and therefore if we're going to have a setter for it, it should go on a base class somewhere.
So can we get a quick re-roll without that setter? Otherwise this looked fine to me, and looks like Alex's other feedback has been addressed.
Comment #72
jibranOk
Comment #73
berdirHm, I don't agree with that.
This is not correct. All entities have a label() *method*, that gives unified access to a label of the entity, which might map to whatever property/field an entity uses for that. For nodes, it's the title (and it therefore has setTitle()), for terms, it's the name (so it has setName()) and so on.
However, for contact forms, the label property is actually called label, so it makes sense to have a corresponding setter for it, just like we have for all other properties.
Comment #74
webchickBerdir and I talked about his concerns in IRC. Basically, while all entities do have a label() method courtesy of EntityInterface, it's not always consistent what this returns. Some entities, such as entity displays, just return NULL and have no label at all. Others, such as User, return the value of the username. Therefore, it's often unclear what setLabel() would actually do in those cases, so throwing it on the base class doesn't really make sense. In this case, however, label is a legit property that you may want to set (though core doesn't seem to have such a case, given the patch only adds the methods).
I'm not super comfortable with only adding it to one arbitrary config entity though and not others that have a similar "profile," because it creates a DX mis-impression (I was not able to find any other examples of config entities that have a setLabel() function in my arbitrary clicking around, so this would introduce inconsistency). So I think I'm still more comfortable going with #72 over #69 at this point, though I'd be very cool w/ a follow-up to discuss how to handle label setters more generally.
With that, committed and pushed to 8.x. Thanks! Also thanks for answering my stupid questions, Berdir. :)