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

CommentFileSizeAuthor
#72 drupal8-expand-contact-form-methods-2030591-72.patch9.91 KBjibran
#72 interdiff.txt1.36 KBjibran
#69 drupal8-expand-contact-form-methods-2030591-69.patch10.2 KBjibran
#66 drupal8-expand-contact-form-methods-2030591-66.patch10.3 KBl0ke
#64 interdiff-63-64.txt2.78 KBmartin107
#64 drupal8-expand-category-methods-2030591-64.patch17.03 KBmartin107
#63 interdiff.txt1.57 KBmartin107
#63 drupal8-expand-category-methods-2030591-63.patch17.57 KBmartin107
#61 interdiff.txt1.42 KBmartin107
#61 drupal8-expand-category-methods-2030591-61.patch16.01 KBmartin107
#59 drupal8-expand-category-methods-2030591-59.patch15.99 KBmartin107
#53 drupal8-expand-category-methods-2030591-53.patch12.69 KBtemoor
#53 interdiff-47-53.txt3.7 KBtemoor
#47 drupal8-expand-category-methods-2030591-47.patch12.99 KBmartin107
#47 interdiff-45-47.txt3.07 KBmartin107
#45 drupal8-expand-category-methods-2030591-45.patch9.91 KBandypost
#45 interdiff.txt8.98 KBandypost
#44 interdiff-40-44.txt512 bytesmartin107
#44 drupal8-expand-category-methods-2030591-44.patch9.01 KBmartin107
#40 drupal8-expand-category-methods-2030591-40.patch9 KBl0ke
#37 drupal8-expand-category-methods-2030591-37.patch9.15 KBpushpinderchauhan
#37 interdiff-2030591-32-37.txt1.48 KBpushpinderchauhan
#33 expand-category-methods-2030591-32.patch9.18 KBmartin107
#29 expand-category-methods-2030591-29.patch9.49 KBpcambra
#28 expand-category-methods-2030591-28.patch9.49 KBsharique
#25 expand-category-methods-2030591-23.patch9.82 KBsharique
#23 expand-category-methods-2030591-23.patch3.04 KBpiyuesh23
#21 expand-category-methods-2030591-21.patch6.71 KBpiyuesh23
#20 expand-category-methods-2030591-18.patch6.78 KBsharique
#18 block-entity-weight-property-methods-2030571-18.patch3.21 KBsharique
#12 expand-category-methods-2030591-11.patch6.79 KBkgoel
#5 expand-category-methods-2030591-5.patch6.8 KBkgoel

Comments

kgoel’s picture

Assigned: Unassigned » kgoel

Going to work on this.

yesct’s picture

@kgoel Did you have any questions or intermediate work to post?

kgoel’s picture

@YesCT I am going to look at other similar patches and work on this today.

kgoel’s picture

Working on this now.

kgoel’s picture

Status: Active » Needs review
StatusFileSize
new6.8 KB

Status: Needs review » Needs work
Issue tags: -Novice, -Entity Field API

The last submitted patch, expand-category-methods-2030591-5.patch, failed testing.

ivan zugec’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Novice, +Entity Field API

The last submitted patch, expand-category-methods-2030591-5.patch, failed testing.

kgoel’s picture

I 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.

kgoel’s picture

Thanks Daffie!

kgoel’s picture

Issue summary: View changes
StatusFileSize
new6.79 KB
kgoel’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: expand-category-methods-2030591-11.patch, failed testing.

The last submitted patch, 12: expand-category-methods-2030591-11.patch, failed testing.

daffie’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: expand-category-methods-2030591-11.patch, failed testing.

sharique’s picture

Here is updated patch, it still need some work.

sharique’s picture

Status: Needs work » Needs review

Forgot to change the status.

sharique’s picture

Assigned: kgoel » sharique
StatusFileSize
new6.78 KB

Added wrong patch, adding correct patch.

piyuesh23’s picture

StatusFileSize
new6.71 KB

@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.

The last submitted patch, 20: expand-category-methods-2030591-18.patch, failed testing.

piyuesh23’s picture

StatusFileSize
new3.04 KB

Adding back the test class from patch in comment#11.

Status: Needs review » Needs work

The last submitted patch, 23: expand-category-methods-2030591-23.patch, failed testing.

sharique’s picture

StatusFileSize
new9.82 KB

Added missing test file provided by kgoel, to last patch.

sharique’s picture

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

martin107’s picture

Looking at CategoryMethodsTest I see nothing defines $this->category
I think you needed an entity_create() before you start asserting things

sharique’s picture

Status: Needs work » Needs review
StatusFileSize
new9.49 KB

Updated patch. Fixed failing tests.

pcambra’s picture

StatusFileSize
new9.49 KB

Re roll as CategoryListController is now CategoryListBuilder

andypost’s picture

  1. +++ b/core/modules/contact/lib/Drupal/contact/Entity/Category.php
    @@ -63,18 +65,77 @@ class Category extends ConfigEntityBase implements CategoryInterface {
    -  public $reply = '';
    +  public $reply;
    ...
    -  public $weight = 0;
    +  public $weight;
    

    any reason to drop default values?

  2. +++ b/core/modules/contact/lib/Drupal/contact/Tests/CategoryMethodsTest.php
    @@ -0,0 +1,90 @@
    +class CategoryMethodsTest extends WebTestBase {
    

    makes sense as unittest

daffie’s picture

Should the function setLabel be:

  public function setLabel($label) {
    $this->set('label', $label);
    return $this;
  }

Instead of:

  public function setLabel($label) {
    return $this->set('label', $label);
  }
tim-e’s picture

Status: Needs review » Needs work
martin107’s picture

StatusFileSize
new9.18 KB

Just a reroll...

martin107’s picture

Status: Needs work » Needs review
tim-e’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/contact/src/Entity/Category.php
    @@ -50,7 +51,7 @@ class Category extends ConfigEntityBundleBase implements CategoryInterface {
    +   * The human-readable label of this catagory.
    

    Bit of a nitpick, sorry but got a typo here.

  2. +++ b/core/modules/contact/src/Entity/Category.php
    @@ -64,17 +65,76 @@ class Category extends ConfigEntityBundleBase implements CategoryInterface {
    +   * An auto-reply message
    

    Missing full stop?

  3. +++ b/core/modules/contact/src/Entity/Category.php
    @@ -64,17 +65,76 @@ class Category extends ConfigEntityBundleBase implements CategoryInterface {
    +  public $reply;
    

    As andypost pointed out, any reason to remove the defaults?

Just a couple minor things.

tim-e’s picture

oh also +1 for andypost's comment #30 - "makes sense as unittest"

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new9.15 KB

Did minor correction mention in #35 and #36. Please review updated patch.

Status: Needs review » Needs work

The last submitted patch, 37: drupal8-expand-category-methods-2030591-37.patch, failed testing.

martin107’s picture

Just 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.

 /**
  * Tests get and set methods on the category interface.
+ *
+ * @group Contact
  */
 class CategoryMethodsTest extends DrupalUnitTestBase {
 
@@ -28,14 +30,6 @@ class CategoryMethodsTest extends DrupalUnitTestBase {
    */
   private $category;
 
-  public static function getInfo() {
-    return array(
-      'name' => 'Category get and set methods',
-      'description' => 'Test get and set methods on category interface',
-      'group' => 'Contact',
-    );
-  }
-
   protected function setUp() {
     parent::setUp();
     //$this->installConfig(array('contact'));
l0ke’s picture

Status: Needs work » Needs review
StatusFileSize
new9 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 40: drupal8-expand-category-methods-2030591-40.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 40: drupal8-expand-category-methods-2030591-40.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new9.01 KB
new512 bytes

Summary 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.

andypost’s picture

@martin107 There's no reason to call save() to make sure that set/get works

Let'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

Status: Needs review » Needs work

The last submitted patch, 45: drupal8-expand-category-methods-2030591-45.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB
new12.99 KB

Fixed up a few things.

andypost’s picture

Awesome, +1 to rtbc!
@berdir anything left here?

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/contact/src/CategoryInterface.php
    @@ -14,4 +14,76 @@
    +  /**
    +   * Returns the category label.
    +   *
    +   * @return string
    +   *   The category label.
    +   */
    +  public function getLabel();
    
    +++ b/core/modules/contact/src/Entity/Category.php
    @@ -47,34 +48,93 @@ class Category extends ConfigEntityBundleBase implements CategoryInterface {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getLabel() {
    +    return $this->get('label');
    +  }
    

    Is this really needed - we have a label() method already?

  2. +++ b/core/modules/contact/src/CategoryInterface.php
    @@ -14,4 +14,76 @@
    +  /**
    +   * Sets the category label.
    +   *
    +   * @param string $label
    +   *   The desired label.
    +   *
    +   * @return $this
    +   */
    +  public function setLabel($label);
    ...
    +  /**
    +   * Sets list of recipient e-mail addresses.
    +   *
    +   * @param array $recipients
    +   *   The desired list of e-mail addresses of this category.
    +   *
    +   * @return $this
    +   */
    +  public function setRecipients($recipients);
    ...
    +  /**
    +   * Sets an auto-reply message to send to the message author.
    +   *
    +   * @param string $reply
    +   *   The desired reply.
    +   *
    +   * @return $this
    +   */
    +  public function setReply($reply);
    ...
    +  /**
    +   * Sets the weight.
    +   *
    +   * @param int $weight
    +   *   The desired weight.
    +   *
    +   * @return $this
    +   */
    +  public function setWeight($weight);
    
    +++ b/core/modules/contact/src/Entity/Category.php
    @@ -47,34 +48,93 @@ class Category extends ConfigEntityBundleBase implements CategoryInterface {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setLabel($label) {
    +    return $this->set('label', $label);
    +  }
    ...
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setRecipients($recipients) {
    +    $this->set('recipients', $recipients);
    +    return $this;
    +  }
    ...
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setReply($reply) {
    +    $this->set('reply', $reply);
    +    return $this;
    +  }
    ...
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setWeight($weight) {
    +    $this->set('weight', $weight);
    +    return $this;
    +  }
    

    These setter's are never used (outside of a test added by this patch) - should we really be adding them?

daffie’s picture

@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.

larowlan’s picture

Assigned: larowlan » Unassigned

+1 to use label() over getLabel()
Happy to keep the setters - no harm in having them, might save a contrib module using reflection :)

temoor’s picture

Removed getLabel() and replaced it with label()

temoor’s picture

Status: Needs work » Needs review

Triggering tests

Status: Needs review » Needs work

The last submitted patch, 53: drupal8-expand-category-methods-2030591-53.patch, failed testing.

larowlan’s picture

note #2285083: Rename contact category to contact form is rtbc which will require a major re-roll here

m1r1k’s picture

Issue tags: +#ams2014contest
berdir’s picture

Title: Expand Category with methods » Expand ContactForm with methods
martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new15.99 KB

Reroll, from last good (#47)

using label() not getLabel()

review from #50 still needs addressing.

Status: Needs review » Needs work

The last submitted patch, 59: drupal8-expand-category-methods-2030591-59.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new16.01 KB
new1.42 KB

Fixed up one of the unit tests.

Other errors persist.

Status: Needs review » Needs work

The last submitted patch, 61: drupal8-expand-category-methods-2030591-61.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new17.57 KB
new1.57 KB

Fixed up errors common to many tests.

martin107’s picture

So a summary of the work needed from #50 combined with this quote from #52

Happy to keep the setters - no harm in having them, might save a contrib module using reflection :)

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.

andypost’s picture

Patch mostly wrong because does not take changes from commited #2285083: Rename contact category to contact form
Also about label there's #2199917: Implement EntityLabeledInterface

  1. +++ b/core/modules/contact/src/CategoryForm.php
    @@ -0,0 +1,126 @@
    + * Base form for category edit forms.
    ...
    +class CategoryForm extends EntityForm {
    

    There's ContactFormEditForm now

  2. +++ b/core/modules/contact/src/CategoryInterface.php
    @@ -0,0 +1,89 @@
    +interface CategoryInterface extends ConfigEntityInterface {
    
    +++ b/core/modules/contact/src/Entity/ContactForm.php
    @@ -11,6 +11,8 @@
    +use Drupal\contact\CategoryInterface;
    
    +++ b/core/modules/contact/tests/src/ContactFormTest.php
    @@ -0,0 +1,73 @@
    + * @coversDefaultClass \Drupal\contact\Entity\Category
    ...
    +    $this->category = new ContactForm(array(), 'contact_category');
    

    Here's ContactFormInterface to extend and ContactForm entity

l0ke’s picture

Status: Needs work » Needs review
Issue tags: -
StatusFileSize
new10.3 KB

Just 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?

Status: Needs review » Needs work

The last submitted patch, 66: drupal8-expand-contact-form-methods-2030591-66.patch, failed testing.

jibran’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new10.2 KB

Fix the whitespace issue and just a simple reroll. I think the additional setters are fine here. This is ready to go so RTBC.

jibran’s picture

webchick’s picture

Status: Reviewed & tested by the community » Needs work

I 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.

jibran’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.36 KB
new9.91 KB

Ok

berdir’s picture

Hm, I don't agree with that.

because it's a property that's found on all entities

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.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Berdir 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. :)

  • webchick committed da94c06 on 8.0.x
    Issue #2030591 by jibran, Temoor, andypost, lokeoke, er.pushpinderrana,...

Status: Fixed » Closed (fixed)

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