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 2030641-expand-filterformat-with-methods-72.patch12.29 KBcalebtr
#72 interdiff-2030641-70-72.txt702 bytescalebtr
#70 2030641-expand-filterformat-with-methods-70.patch12.98 KBcalebtr
#66 interdiff-2030641-64-66.txt7.8 KBcalebtr
#66 2030641-expand-filterformat-with-methods-66.patch23.46 KBcalebtr
#64 interdiff-2030641-62-64.txt1.17 KBcalebtr
#64 2030641-expand-filterformat-with-methods-64.patch24.1 KBcalebtr
#62 2030641-expand-filterformat-with-methods-62.patch23.75 KBcalebtr
#62 interdiff-2030641-58-62.txt480 bytescalebtr
#62 interdiff-2030641-60-62.txt9.18 KBcalebtr
#60 2030641-expand-filterformat-with-methods-60.patch31.44 KBcalebtr
#60 interdiff-2030641-58-60.txt8.71 KBcalebtr
#58 2030641-expand-filterformat-with-methods-58.patch23.52 KBcalebtr
#58 interdiff-2030641-56-58.txt465 bytescalebtr
#56 2030641-expand-filterformat-with-methods-56.patch23.52 KBcalebtr
#56 interdiff-2030631-54-56.txt416 bytescalebtr
#54 interdiff-2030641-51-54.txt1.85 KBcalebtr
#54 2030641-expand-filterformat-with-methods-54.patch23.52 KBcalebtr
#51 interdiff-2030641-48-51.txt1.26 KBcalebtr
#51 2030641-expand-filterformat-with-methods-51.patch23.17 KBcalebtr
#48 2030641-expand-filterformat-with-methods-48.patch23.17 KBcalebtr
#48 interdiff-2030641-44-48.txt468 bytescalebtr
#44 interdiff-2030641-42-44.txt954 bytescalebtr
#44 2030641-expand-filterformat-with-methods-44.patch23.38 KBcalebtr
#42 2030641-expand-filterformat-with-methods-35.patch23.4 KBcalebtr
#42 interdiff-2030641-37-42.txt22.61 KBcalebtr
#38 interdiff.35.37.txt507 bytesyesct
#37 2030641-expand-filterformat-with-methods-37.patch6.73 KBcalebtr
#37 interdiff-2030641-35-37.txt0 bytescalebtr
#35 interdiff-2030641-29-35.txt1.27 KBcalebtr
#35 2030641-expand-filterformat-with-methods-35.patch6.73 KBcalebtr
#29 interdiff-2030641-27-29.txt1.46 KBcalebtr
#29 2030641-expand-filterformat-with-methods-29.patch5.46 KBcalebtr
#27 2030641-expand-filterformat-with-methods-27.patch5.5 KBcalebtr
#25 interdiff-2030641-21-25.txt1.78 KBpushpinderchauhan
#25 FilterFormat_methods-2030641-25.patch5.47 KBpushpinderchauhan
#21 FilterFormat_methods-2030641-21.patch5.73 KBlahoosascoots
#19 FilterFormat_methods-2030641-19.patch4.54 KBlahoosascoots
#13 FilterFormat_methods-2030641-13.patch5.84 KBivan zugec
#13 interdiff.txt6.42 KBivan zugec
#11 FilterFormat_methods-2030641-11.patch3.82 KBivan zugec
#9 FilterFormat-methods-2030641-9.patch3.84 KBjlindsey15
#7 FilterFormat-methods-2030641-7.patch3.84 KBjlindsey15
#4 FilterFormat-methods-2030641-2.patch1.65 KBjlindsey15
#2 FilterFormat-methods-2030641-2.patch1.68 KBjlindsey15

Comments

jlindsey15’s picture

Assigned: Unassigned » jlindsey15

This is my first contribution to Drupal - gotta start somewhere!

jlindsey15’s picture

Status: Active » Needs review
StatusFileSize
new1.68 KB

This isn't complete yet (only added one getter method), but since this is my first time here I just want to go through the patching process to make sure I can do it. More to come later...

Status: Needs review » Needs work

The last submitted patch, FilterFormat-methods-2030641-2.patch, failed testing.

jlindsey15’s picture

StatusFileSize
new1.65 KB
jlindsey15’s picture

Status: Needs work » Needs review
jlindsey15’s picture

Status: Needs review » Needs work

As stated before, the last patch isn't complete.

jlindsey15’s picture

Status: Needs work » Needs review
StatusFileSize
new3.84 KB

Okay it should be done (hopefully). Pretend those first two patches don't even exist... I had no idea what I was doing for a little bit :)

Status: Needs review » Needs work

The last submitted patch, FilterFormat-methods-2030641-7.patch, failed testing.

jlindsey15’s picture

Status: Needs work » Needs review
StatusFileSize
new3.84 KB

Oops, some weird typos in the last one.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
    @@ -49,4 +49,80 @@ public function setFilterConfig($instance_id, array $configuration);
    +   * Returns the cache value (whether processed text of this format can be cached).
    +   *
    +   * @return bool
    +   *   The cache value
    +   */
    +  public function getCache();
    

    let's name this isCacheable().

    Then you can just leave out the Returns part and just have "Whether ..." and the @return should say something like Returns TRUE if ...

  2. +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
    @@ -49,4 +49,80 @@ public function setFilterConfig($instance_id, array $configuration);
    +   * Returns the format's FilterBag (holds the collection of filters that are attached to this format).
    

    The first line shouldn't be longer than 80 characters, so the explanation sentence should be on the next line, like this:

    Returns the formats filter bag.

    The filter bag holds the ... .

  3. +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
    @@ -49,4 +49,80 @@ public function setFilterConfig($instance_id, array $configuration);
    +   * @return \Drupal\filter\FilterBag
    +   *   The form
    

    That looks incomplete ;)

  4. +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
    @@ -49,4 +49,80 @@ public function setFilterConfig($instance_id, array $configuration);
    +    * @param int $newWeight
    +    *   The desired weight.
    ...
    +  public function setWeight($newWeight);
    

    variables in methods usually still use $new_weight, I also think just $weight is enough.

  5. +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php
    @@ -139,6 +139,66 @@ public function id() {
    +	return this;
    

    Looks like you have a tab instead of spaces here.

ivan zugec’s picture

StatusFileSize
new3.82 KB

Rerolling patch from #9 so it works with HEAD.

The next patch will have the changes from #10.

kgoel’s picture

Status: Needs work » Needs review

changing status

ivan zugec’s picture

Assigned: jlindsey15 » Unassigned
StatusFileSize
new6.42 KB
new5.84 KB

Attached patch implements changes mentioned in #10. I also created a test class, copied from the "FilterCrudTest" class, for the methods.

I removed the "get/setFilterBag" method because it looks like the filter_bag is handled within the filters() method.

ivan zugec’s picture

Quick question, should patches for #2016679: Expand Entity Type interfaces to provide methods, protect the properties have tests?

It looks like some do and some don't.

For example, the following patches do not have tests:

- #2015123: Expand NodeInterface to provide getters and setters
- #2026347: Adding methods to UserInterface/AccountInterface

And the following do have patches:

- #1983548: Convert contact message entities to the new Entity Field API
- #1818568: Convert files to the new Entity Field API

Anyhow, the #13 patch does have a test class. I simply copied the existing "FilterCrudTest" class and created a new class called "FilterFormatMethodsTest".

Also, the "FilterFormatMethodsTest" test class needs to be updated to follow the latest testing coding standards:

- Test methods should be public.
- And, the @file declaration needs to be updated.

Check out https://drupal.org/node/325974 for more details.

ivan zugec’s picture

Assigned: Unassigned » ivan zugec
daffie’s picture

@Ivan Zugec: I think that a lot/all of underlying postponing problems are solved. Are you still willing to work on this issue?

daffie’s picture

linl’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies, tagging for reroll.

lahoosascoots’s picture

Status: Needs work » Needs review
StatusFileSize
new4.54 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 19: FilterFormat_methods-2030641-19.patch, failed testing.

lahoosascoots’s picture

Status: Needs work » Needs review
StatusFileSize
new5.73 KB

Ah, the deleted file got renamed. Added in the missing required functions.

lahoosascoots’s picture

Issue tags: -Needs reroll
daffie’s picture

Assigned: ivan zugec » Unassigned
berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,79 @@
    + * Definition of Drupal\filter\Tests\FilterFormatMethodsTest.
    

    This should be Contains \Drupal\...

  2. +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,79 @@
    +class FilterFormatMethodsTest extends DrupalUnitTestBase {
    

    DrupalUnitTestBase is now KernelTestBase.

  3. +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,79 @@
    +  public static function getInfo() {
    +    return array(
    +      'name' => 'Filter format get and set methods',
    +      'description' => 'Test get and set methods on text format interface.',
    +      'group' => 'Filter',
    +    );
    +  }
    

    getInfo() no longer exists, instead add @group on the class docblock, remove everything else.

  4. +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,79 @@
    +  function setUp() {
    

    This should have an @inheritdoc

  5. +++ b/core/modules/filter/src/FilterFormatInterface.php
    @@ -84,4 +84,61 @@ public function getFilterTypes();
    +   * @return \Drupal\filter\FilterFormatInterface
    +   *   The class instance this method is called on.
    

    This is now return $this, without description.

Cache stuff no longer exists.

pushpinderchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new5.47 KB
new1.78 KB

Please review updated patch with fixed points as @Berdir suggested in #24.

calebtr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch in #25 no longer applies. I will attempt a re-roll.

calebtr’s picture

I followed the re-roll instructions at https://www.drupal.org/patch/reroll. I got no conflicts and an automatic 3-way merge.

calebtr’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
calebtr’s picture

I moved core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php to core/modules/filter/src/Tests/FilterFormatMethodsTest.php where the other tests live .

I also added some blank lines and made other small changes per the coding standards for files at per https://www.drupal.org/coding-standards/docs#file and for tests per https://www.drupal.org/node/325974.

Status: Needs review » Needs work

The last submitted patch, 29: 2030641-expand-filterformat-with-methods-29.patch, failed testing.

calebtr’s picture

The failed test calls a property that was renamed with https://www.drupal.org/node/1533250.

I'm wee baffled as to why it didn't break anything before now.

I'll fix the test and give it another try.

Edit: I was wrong about where the $timestamp_now property got changed because it is still there in Drupal\locale\Tests\LocaleUpdateBase. So my next tack is to see if use Drupal\locale\Tests\LocaleUpdateBase will help.

calebtr’s picture

Aha, I see now that $this->timestamp_now it is set in Drupal\locale\Tests\LocaleUpdateBase::setUp() but not actually defined anywhere, which is where patch #29, above, fails.

But if it is defined, it needs to be defined as $timestampNow per the naming conventions at https://www.drupal.org/node/608152, and I can grep to find where else it needs to be changed.

Alternatively, since this is set to REQUEST_TIME in Drupal\locale\Tests\LocaleUpdateBase::setUp(), do we even need it? Why not just use the REQUEST_TIME constant in Drupal\locale\Tests\LocaleUpdateTest::testUpdateImportSourceRemote() (where the test failed)?

If we do need it, I think if it will be helpful to rename the property to $timestampRequestTime to avoid visual confusion between $timestampNow and $timestampNew.

Can we resolve this here, or is this a good case for a new issue?

calebtr’s picture

I spoke with YesCT in-person about the failed test. We agreed we should figure out what was making the test fail before making any new issues or changing anything else.

I ran LocaleUpdateTest on a local installed site and it passed against 8.0.x and my branch with this patch.

I am re-queing the patch for testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new6.73 KB
new1.27 KB

Okay, #29 passed the second time around, but I found one more test that called ->get() and ->set().

In summary:

  • adds getter and setter methods to replace public properties on the FilterFormat class and interface and related tests
  • moves core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php to correct directory
  • adds added some blank lines and made other small changes per the coding standards for files at per https://www.drupal.org/coding-standards/docs#file and for tests per https://www.drupal.org/node/325974.

I also double-checked that the patch still applies on an up-to-date 8.0.x branch.

Status: Needs review » Needs work

The last submitted patch, 35: 2030641-expand-filterformat-with-methods-35.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new6.73 KB

Here is a fix for the PHP error in #35.

yesct’s picture

StatusFileSize
new507 bytes

just noting the interdiff to help with review.

yesct’s picture

Status: Needs review » Needs work

1.
No properties are being protected. We need to do that to be able to find the direct accesses of the properties in core and have them use the methods (and we can then tell ... maybe we wont need a method).

2.

+++ b/core/modules/filter/src/Entity/FilterFormat.php
@@ -128,6 +128,52 @@ public function id() {
+  public function setCache($cache) {
+    $this->set('cache', $cache);
+    return $this;

why is this doing the set() instead of just access the property directly (it can, cause it is the class itself)

calebtr’s picture

I saw this comment in the 'Extend Block with methods()' issue I was working on - https://www.drupal.org/node/2030571#comment-7607017 - this explains why the properties are left as public.

Thoughts?

yesct’s picture

Yeah, that was a long time ago. And we have tightened up our approach since then.

We should still make them protected.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new22.61 KB
new23.4 KB

Drupal\Core\Config\Entity\ConfigEntityBase::set() does more than just set the value:

/**
   * {@inheritdoc}
   */
  public function set($property_name, $value) {
    if ($this instanceof EntityWithPluginCollectionInterface) {
      $plugin_collections = $this->getPluginCollections();
      if (isset($plugin_collections[$property_name])) {
        // If external code updates the settings, pass it along to the plugin.
        $plugin_collections[$property_name]->setConfiguration($value);
      }
    }

    $this->{$property_name} = $value;

    return $this;
  }

My assumption is that instanceof EntityWithPluginCollectionInterface is going to evaluate true here because class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, EntityWithPluginCollectionInterface, so we should keep using ->set().

I protected the properties. The $format and $name properties have @todo labels indicating the properties need to be renamed to $id and $label respectively. I didn't do that, but I did add the getters and setters with the assumption that these properties will be renamed (ie setId(), setLabel(), getLabel()).

I searched to see if there was an issue related to renaming the properties but didn't find one. I'm not sure of the relationship between @todo and issues. The todos should be trivial to implement once the properties have been protected. I did see the comments in the parent issue (#18 and #53) regarding that $id can be a protected.

I expect this will get back to Needs Work, but lets see what the tests say anyway.

Status: Needs review » Needs work

The last submitted patch, 42: 2030641-expand-filterformat-with-methods-35.patch, failed testing.

calebtr’s picture

Resolving this PHP error and one more.

calebtr’s picture

Status: Needs work » Needs review

And here is where I remember to change the status to Needs review.

Status: Needs review » Needs work

The last submitted patch, 44: 2030641-expand-filterformat-with-methods-44.patch, failed testing.

calebtr’s picture

Ok yeah so it looks like we don't want to protect $format after all. Whoops. I'll keep working on this.

calebtr’s picture

Making $format a public property again.

calebtr’s picture

Status: Needs work » Needs review

...and setting to Needs Review again

Status: Needs review » Needs work

The last submitted patch, 48: 2030641-expand-filterformat-with-methods-48.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new23.17 KB
new1.26 KB

Fixing PHP warning.

I think this will pass.

There's still two points that I see that need clarifying:

1: whether setters need to call set() or not. I think yes, but I think the counter-argument is that if we set properties directly and no tests fail then it is fine.

2: $name property is to be renamed $label, so it is affected by getLabel() and setLabel(); similarly $format property is to be renamed $id, so is affected by id() and setId().

Summary of what this patch does:

  • adds getter and setter methods to replace public properties on the FilterFormat class, interface and related tests
  • moves core/modules/filter/lib/Drupal/filter/Tests/FilterFormatMethodsTest.php to correct directory
  • adds added some blank lines and made other small changes per the coding standards for files at per https://www.drupal.org/coding-standards/docs#file and for tests per https://www.drupal.org/node/325974.
  • leaves $format (to be renamed to $id) as a public property
calebtr’s picture

Issue tags: +Needs reroll

needs reroll.

calebtr’s picture

Issue tags: -Needs reroll

Wrong issue.

calebtr’s picture

I'm changing all the setters per YesCT's advice.

I changed FilterFormat::name to FilterFormat::label.

Status: Needs review » Needs work

The last submitted patch, 54: 2030641-expand-filterformat-with-methods-54.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new416 bytes
new23.52 KB

Completing change of $name property to $label.

Status: Needs review » Needs work

The last submitted patch, 56: 2030641-expand-filterformat-with-methods-56.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new465 bytes
new23.52 KB

Used the wrong method in last patch.

Status: Needs review » Needs work

The last submitted patch, 58: 2030641-expand-filterformat-with-methods-58.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new8.71 KB
new31.44 KB

I found a bunch more places where label() needed to be getLabel().

Status: Needs review » Needs work

The last submitted patch, 60: 2030641-expand-filterformat-with-methods-60.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new9.18 KB
new480 bytes
new23.75 KB

New approach, undoing changes #60. I'm also including an interdiff from 58 because I think it will be more helpful.

Status: Needs review » Needs work

The last submitted patch, 62: 2030641-expand-filterformat-with-methods-62.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new24.1 KB
new1.17 KB

Renaming $name to $label may be beyond the scope of the issue, but in case it is not, here is another try.

Status: Needs review » Needs work

The last submitted patch, 64: 2030641-expand-filterformat-with-methods-64.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new23.46 KB
new7.8 KB

switching all of the times I added getLabel() back to label(). This is a replacement for accessing $name directly.

Status: Needs review » Needs work

The last submitted patch, 66: 2030641-expand-filterformat-with-methods-66.patch, failed testing.

yesct’s picture

yeah... why renaming name to label?
we should just be making it protected.
the @todo's to do the renaming sound like separate issues to me.

and what is the deal with the format property?

yesct’s picture

Issue tags: -Novice

I suspect that the setId() is only used in tests and we can and should get rid of it and instead change the tests to create new things with different ids. same with setLabel. (changing the tests can be a separate issue if that is helpul)

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new12.98 KB

Ok, going back to #37 (51 failed tests on re-roll) and changing only:

- setters set properties directly instead of using ->set
- a bunch of places and tests where $weight should be getWeight

For now I let $format and $name public so setLabel(0 and setId() are dropped.

I'm unable to get an interdiff here.

Status: Needs review » Needs work

The last submitted patch, 70: 2030641-expand-filterformat-with-methods-70.patch, failed testing.

calebtr’s picture

Status: Needs work » Needs review
StatusFileSize
new702 bytes
new12.29 KB

Undoing changes to FilterPluginCollection.php - this extends a different class entirely.

Status: Needs review » Needs work

The last submitted patch, 72: 2030641-expand-filterformat-with-methods-72.patch, failed testing.

berdir’s picture

  1. +++ b/core/modules/filter/src/Entity/FilterFormat.php
    @@ -128,6 +128,52 @@ public function id() {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getRoles() {
    +    return $this->roles;
    +  }
    ...
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setRoles($roles) {
    +    $this->roles = $roles;
    +    return $this;
    +  }
    

    See the property documentation. There is no point in having setters and getters for this, the only use case is for initial default configuration. So I think this should not exist.

  2. +++ b/core/modules/filter/src/Entity/FilterFormat.php
    @@ -128,6 +128,52 @@ public function id() {
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function isCacheable() {
    +    return $this->cache > 0;
    +  }
    ...
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setCache($cache) {
    +    $this->cache = $cache;
    +    return $this;
    +  }
    

    This property/concept no longer exists and the methods should be removed.

  3. +++ b/core/modules/filter/src/Tests/FilterDefaultConfigTest.php
    @@ -40,13 +40,13 @@ function testInstallation() {
         // Verify that the loaded format does not contain any roles.
    -    $this->assertEqual($format->get('roles'), NULL);
    +    $this->assertEqual($format->getRoles(), NULL);
         // Verify that the defined roles in the default config have been processed.
    

    The roles tests can stay as they are, with set/get.

  4. +++ b/core/modules/filter/src/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,78 @@
    +    $this->format->format = 'custom_format';
    +    $this->format->name = 'Custom format';
    

    I'm not sure about those two. I didn't read the discussion above.

    Making it protected might still be a good idea. You can still use set()/get() or you can pass it as part of the $values array in entity_create().

  5. +++ b/core/modules/filter/src/Tests/FilterFormatMethodsTest.php
    @@ -0,0 +1,78 @@
    +   * Tests weight get and set method.
    +   */
    +  function testGetWeight() {
    

    Kernel tests are not as fast as unit tests. I'm not sure if we should write them as unit tests and have every method separate. Maybe a single test method would make more sense.

yesct’s picture

I'm confused about #74 3.
I think the tests should be re-written to respect the protectedness of the property.

yesct’s picture

yeah, the cached property was removed in #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags

it might be worth just making the properties protected and seeing what fails, and just fixing those fails.

daffie’s picture

mile23’s picture

Issue tags: +Needs re-roll

Patch does not apply.

yesct’s picture

Status: Needs work » Closed (duplicate)
mile23’s picture

Issue tags: -Needs re-roll