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

Comments

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new4.63 KB

I was thinking of menu_link, not menu...

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
berdir’s picture

Status: Needs review » Needs work

Hm, I do agree that getLangcode() (although that doesn't really match with most other EntityInterface methods, e.g. language()) would be useful, but seems like the wrong issue to add it :)

Also won't apply anymore.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
slv_’s picture

Assigned: Unassigned » slv_

Giving this a go, if that's ok!

slv_’s picture

Got a patch for this, bit airport's WiFi said no more WiFi for the laptop. Will upload it tonight!

slv_’s picture

StatusFileSize
new3.73 KB

Patch attached.

slv_’s picture

slv_’s picture

Re-testing to see if it still passes. Any feedback? =)

slv_’s picture

Issue tags: -Novice, -Entity Field API
mike.davis’s picture

The main thing I can see is:

+++ b/core/modules/system/lib/Drupal/system/Entity/Menu.php
@@ -59,7 +59,7 @@ class Menu extends ConfigEntityBase implements MenuInterface {
+  protected $description;

This member variable needs to be reverted back to being public for the patch - https://drupal.org/node/2016679#comment-7616179

miraj9093’s picture

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

patch is not applying ...

miraj9093’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.92 KB

patche rerolled

Status: Needs review » Needs work

The last submitted patch, 14: 2030645.patch, failed testing.

l0ke’s picture

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

Reroll the patch.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Is there a reason we do have this setter method even nothing in core uses it? I would though agree that for consistency introducing them would be great idea!

m1r1k’s picture

Issue tags: +#ams2014contest
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/Entity/Menu.php
@@ -60,8 +60,31 @@ class Menu extends ConfigEntityBase implements MenuInterface {
+  /**
+   * {@inheritdoc}
+   */
+  public function setDescription($description) {
+    $this->description = $description;
+    return $this;
+  }
...
+  /**
+   * {@inheritdoc}
+   */
+  public function setLocked($locked) {
+    $this->locked = $locked;
+    return $this;
+  }

+++ b/core/modules/system/src/MenuInterface.php
@@ -15,6 +15,25 @@
+  /**
+   * Sets the description of the menu.
+   *
+   * @param string $description
+   *   The menu description.
+   *
+   * @return \Drupal\system\MenuInterface
+   *   The called menu entity.
+   */
+  public function setDescription($description);

@@ -22,4 +41,15 @@
+  /**
+   * Sets the locked status of a menu.
+   *
+   * @param bool $locked
+   *   TRUE to set the menu as locked, FALSE to set it as unlocked.
+   *
+   * @return \Drupal\system\MenuInterface
+   *   The called menu entity.
+   */
+  public function setLocked($locked);

We have not been adding setters that are completely unused in the other issues.

Can this issue also protect the id and label properties? Thanks.

joecodes’s picture

Maybe we should set those as private methods? Btw latest patch patched cleanly (comment #16)

l0ke’s picture

Status: Needs work » Needs review
StatusFileSize
new3.77 KB
new1.92 KB

Removed setters. Make id and label properties protected.

Status: Needs review » Needs work

The last submitted patch, 21: expand-menu-with-methods-2030645-21.patch, failed testing.

l0ke’s picture

Assigned: slv_ » Unassigned
Status: Needs work » Needs review
StatusFileSize
new82.26 KB
new595 bytes

Whoops, missed this label usage in test.

mile23’s picture

Issue tags: -
StatusFileSize
new85.85 KB

Reroll with conflicts resolved. Let's see if the testbot disagrees with my reroll-fu.

Status: Needs review » Needs work

The last submitted patch, 24: expand-menu-with-methods-2030645-24.patch, failed testing.

mile23’s picture

It looks like the patch in #24 includes out-of-scope changes.

Will now re-roll #21 and include interdiff from #23.

mile23’s picture

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

OK, so reroll with patch from #21 and interdiff from #23, rebased to 8.0.x. Success with zero conflicts.

mile23’s picture

Status: Needs review » Needs work
+++ b/core/modules/menu_ui/src/Tests/MenuCacheTagsTest.php
@@ -60,7 +60,7 @@ public function testMenuBlock() {
     // Verify that after modifying the menu, there is a cache miss.
     $this->pass('Test modification of menu.', 'Debug');
-    $menu->label = 'Awesome llama';
+    $menu->set('label', 'Awesome llama');
     $menu->save();
     $this->verifyPageCache($path, 'MISS');

YesCT says this test needs to be refactored, to figure out if we need a setLabel().

This is as far as we got looking at the patch, will come back later.

mile23’s picture

Status: Needs work » Needs review

Since the point of the test is to show the cache miss, and since I can't find any instances of using set('label') within the menu_ui module, I'd say it's safe to not add a setter for label.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

In case we would like to have we should start to think about introducing one on the base entity level.

alexpott’s picture

Category: Task » Bug report
Status: Reviewed & tested by the community » Fixed

Reclassifying as a bug since exposure of properties as public allows code to not use the API eg ->id vs ->id(). This makes Drupal more stable and prevents bugs. Nice work.

Committed b34bcec and pushed to 8.0.x. Thanks!

  • alexpott committed b34bcec on 8.0.x
    Issue #2030645 by lokeoke, Mile23, tim.plunkett, miraj9093, slv_ |...

Status: Fixed » Closed (fixed)

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

yesct’s picture

Did we want a test for getDescription() ?