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

postponed until this is solved: #2271529: Move breakpoint settings to theme and module *.breakpoints.yml files at root level if it is done this issue is irrelevant

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc’s picture

Title: Copy of Expand BreakpointGroup with methods » Expand BreakpointGroup with methods

Ups, change title

Michael Hodge Jr’s picture

Assigned: Unassigned » Michael Hodge Jr
Michael Hodge Jr’s picture

Assigned: Michael Hodge Jr » Unassigned
slv_’s picture

Assigned: Unassigned » slv_

I'll try and take a look to this.

xeniak’s picture

This may (or may not :)) help.

xeniak’s picture

Status: Active » Needs review

Summoning test-bot.

Status: Needs review » Needs work

The last submitted patch, drupal8.breakpoint-module.2030587-5.patch, failed testing.

ReeceMarsland’s picture

I'm working on this as part of the prague sprint.

slv_’s picture

Er... I was just on it (assigned yesterday)... re prague (see #4), but np. Will just walk away.

slv_’s picture

Assigned: slv_ » Unassigned
ReeceMarsland’s picture

Assigned: Unassigned » slv_

The error thrown during install:

Recoverable fatal error: Argument 1 passed to Drupal\breakpoint\Entity\BreakpointGroup::setBreakpoints() must be an array, null given, called in /projects/drupal8/www_2030587/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php on line 225 and defined in Drupal\breakpoint\Entity\BreakpointGroup->setBreakpoints() (line 100 of /projects/drupal8/www_2030587/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php).

xeniak’s picture

Status: Needs work » Needs review
FileSize
12.99 KB

Thanks, Reece. That helped.

Status: Needs review » Needs work

The last submitted patch, drupal8.breakpoint-module.2030587-12.patch, failed testing.

slv_’s picture

Assigned: slv_ » Unassigned
rhm5000’s picture

Status: Needs work » Needs review
FileSize
4.67 KB
12.79 KB

Code Cleanup:

  • Removed extra spaces near conditionals and method parameters.
  • Added comma to last element in array

Status: Needs review » Needs work

The last submitted patch, drupal-2030587-breakpoint-module-15.patch, failed testing.

rhm5000’s picture

Status: Needs work » Needs review
FileSize
1.23 KB
12.82 KB

Line 53 of /core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php uses empty() with a method instead of a variable, empty() only supports variables, and will causes a phrase error prior to 5.5 see PHP: empty.

Status: Needs review » Needs work

The last submitted patch, drupal-2030587-breakpoint-module-17.patch, failed testing.

xeniak’s picture

Status: Needs work » Needs review
FileSize
21.79 KB

I've added getters and setters, but making the instance variables protected seems to keep the breakpoint group data from being saved. Any help/suggestions would be appreciated.

xeniak’s picture

Removed setId() function.

johnennew’s picture

Status: Needs review » Needs work

Hi @xeniak - some coding standards items in the last patch need cleaning up.

+  /**
    * Checks if the breakpoint group is valid.
    *
    * @throws \Drupal\breakpoint\InvalidBreakpointSourceTypeException
    * @throws \Drupal\breakpoint\InvalidBreakpointSourceException
    *
    * @return bool
-   *   Returns TRUE if the breakpoint group is valid.
+   * Returns TRUE if the breakpoint group is valid.
    */

Lines under an @return or @param need to be indented with two spaces - https://drupal.org/node/1354#return

diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
index 774890d..1d2838a 100644
--- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
@@ -18,22 +18,21 @@
  * Defines the BreakpointGroup entity.
  *
  * @EntityType(
- *   id = "breakpoint_group",
- *   label = @Translation("Breakpoint group"),
- *   module = "breakpoint",
- *   controllers = {
- *     "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
- *   },
- *   config_prefix = "breakpoint.breakpoint_group",
- *   entity_keys = {
- *     "id" = "id",
- *     "label" = "label",
- *     "uuid" = "uuid"
- *   }
+ * id = "breakpoint_group",
+ * label = @Translation("Breakpoint group"),
+ * module = "breakpoint",
+ * controllers = {
+ * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
+ * },
+ * config_prefix = "breakpoint.breakpoint_group",
+ * entity_keys = {
+ * "id" = "id",
+ * "label" = "label",
+ * "uuid" = "uuid"
+ * }
  * )
  */

This indentation is required.

+  /**
+   * {@inheritdoc}
+   */
+  public function setName($name) {
+    return $this->set('name',$name);
+  }

The setters should return the $this object.

+    if (preg_match('/[^a-z0-9_]+/',$name || empty($name))) {

There should be a space after commas in a function call or elements of an array - https://drupal.org/coding-standards#functcall

+    foreach ( $breakpoints as $breakpoint_name ) {

No space after the opening parentheses  of a control structure - https://drupal.org/coding-standards#controlstruct

+      if (! $breakpoint) {

Unary operators (operators that operate on only one value), such as !, should not have a space between the operator and the variable or number they are operating on - https://drupal.org/coding-standards#operators

   public function addBreakpoints($breakpoints) {
-    foreach ($breakpoints as $breakpoint_name) {
+    foreach ( $breakpoints as $breakpoint_name ) {
       // Check if breakpoint exists, assume $breakpoint_name is a machine name.
-      $breakpoint = entity_load('breakpoint', $this->sourceType . '.' . $this->source . '.' . $breakpoint_name);
+      $breakpoint = entity_load('breakpoint',$this->getSourceType() . '.' . $this->getSource() . '.' . $breakpoint_name);
       // If the breakpoint doesn't exist, assume $breakpoint_name is an id.
-      if (!$breakpoint) {
-        $breakpoint = entity_load('breakpoint', $breakpoint_name);
+      if (! $breakpoint) {
+        $breakpoint = entity_load('breakpoint',$breakpoint_name);
       }
       // If the breakpoint doesn't exists, do not add it.
       if ($breakpoint) {
         // Add breakpoint to group.
-        $this->breakpoints[$breakpoint->id()] = $breakpoint;
+        $breakpoints = $this->getBreakpoints();
+        $breakpoints [$breakpoint->id()] = $breakpoint;
+        $this->setBreakpoints($breakpoints);
       }
     }
   }

You are reassigning the $breakpoints variable inside the for loop it is being iterated over in. I think its bad practice to change a variable being looped over within the loop itself like this.

xeniak’s picture

Status: Needs work » Needs review
FileSize
12.67 KB
19.28 KB

Ceng, thanks. Corrections made. On that last one definitely comes under the heading "I don't know what I was thinking."

cosmicdreams’s picture

+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.phpundefined
@@ -102,6 +102,74 @@ public function __construct(array $values, $entity_type) {
   /**
+   * {@inheritdoc}
+   */
+  public function getName() {
+    return $this->get('name');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setName($name) {
+    $this->set('name', $name);
+    return $this;

I've asked this elsewhere but I'll ask this here too.

Why aren't we directly getting or setting properties from within the same object. Do we override the default get or set methods? Why can't we do this:

/**
 * {@inheritdoc}
 */
public function getName() {
  return $this->name;
}

/**
 * {@inheritdoc}
 */
public function setName($name) {
  $this->name =  $name;
  return $this;
}
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.phpundefined
@@ -148,56 +222,64 @@ public function isValid() {
+    $breakpoints [$breakpoint->id()] = $breakpoint;

IMO, there shouldn't be a space between $breakpoint and "["

+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.phpundefined
@@ -148,56 +222,64 @@ public function isValid() {
+    ¶
...
+        $new_breakpoints [$breakpoint->id()] = $breakpoint;        ¶

extra space

cosmicdreams’s picture

+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.phpundefined
@@ -148,56 +222,64 @@ public function isValid() {
-    $this->breakpoints[$breakpoint->id()] = $breakpoint;
+    $breakpoints = $this->getBreakpoints();
+    $breakpoints [$breakpoint->id()] = $breakpoint;
+    $this->setBreakpoints($breakpoints);

I have found this logic in a few places. Maybe we need a setBreakpointById. (See picture module's tests)

Lastly

I don't think all of this work is worth it if you don't change the access modifiers of BreakpointGroup's properties to protected.

mike.davis’s picture

I agree with @cosmicdreams on his last point, that the member variables should be defined as protected now that we are adding all the getters and setters.

With regards to the getters and setters, the idea with these is that you can daisy chain the setters together when calling them, so they should always return $this. The way to access the member variables is by using the available get() and set() methods as detailed in the CodeEntityBase class.

cosmicdreams’s picture

There is no CodeEntityBase in Drupal

mike.davis’s picture

Sorry, I meant ConfigEntityBase

balagan’s picture

Issue summary: View changes
Status: Needs review » Needs work

Does not apply anymore, needs to be rerolled.

Jelle_S’s picture

Status: Needs work » Needs review
FileSize
17.02 KB

Rerolled patch. Should pass all tests (it did on my local machine...)

Status: Needs review » Needs work

The last submitted patch, 29: drupal8.breakpoint-module.2030587-29.patch, failed testing.

Jelle_S’s picture

From #2016679: Expand Entity Type interfaces to provide methods, protect the properties:

Ideally the visibility of the properties which are getters and setters in this case can force people to use the property directly and instead of using it directly, use it as a method so while working on the patch you can make the visibility as protected and change them back to public before RTBC - as stated in this comment

So changing the properties to their default before the patch (as otherwise we'd be introducing an API change (see comment #9 in that issue)

This should also answer #24 & #25

Jelle_S’s picture

Status: Needs work » Needs review
Jelle_S’s picture

Forgot a small change in picture, this one should pass.

The last submitted patch, 31: drupal8.breakpoint-module.2030587-30.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 33: drupal8.breakpoint-module.2030587-31.patch, failed testing.

Jelle_S’s picture

Status: Needs work » Needs review
FileSize
17.67 KB

Grr, missed an other one.

uisc’s picture

fine nice post. thanks

mike.davis’s picture

Status: Needs review » Needs work

Thanks @Jelle_S, I had missed this comment item #9 :), this patch looks good.

+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php
@@ -15,6 +15,99 @@
+   * @return \Drupal\breakpoint\BreakpointGroup\Interface

Something that has been mentioned on other issues within this list, is that the method comments should @return self rather than the interface.

Jelle_S’s picture

Status: Needs work » Needs review
FileSize
17.42 KB

New patch with comments according to #38. Thanks for the review ;-)

Status: Needs review » Needs work

The last submitted patch, 39: drupal8.breakpoint-module.2030587-39.patch, failed testing.

Jelle_S’s picture

Status: Needs work » Needs review

Please behave testbot...
39: drupal8.breakpoint-module.2030587-39.patch queued for re-testing.

stuti.manandhar’s picture

stuti.manandhar’s picture

Assigned: Unassigned » stuti.manandhar
star-szr’s picture

Assigned: stuti.manandhar » Unassigned
Status: Needs review » Needs work
Issue tags: +Needs reroll, +DrupalWorkParty

Unassigning and tagging for reroll.

@stuti.manandhar or @Jelle_S if you want to work on this just reassign to yourself.

daffie’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
17.81 KB
RainbowArray’s picture

This patch looks like it still applies if somebody wants to take a look and review this.

RainbowArray’s picture

pcambra’s picture

filijonka’s picture

Status: Needs review » Needs work

The last submitted patch, 48: expand-breakpointgroup-with-methods-2030587-48.patch, failed testing.

filijonka’s picture

Status: Needs work » Needs review
FileSize
3.38 KB
16.54 KB

rerolled #50 and changed some doc. Not sure I did the interdiffcorrectly but hopefully

dawehner’s picture

  1. +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php
    @@ -25,6 +25,99 @@
    +   * @return self
    +   *   The called breakpoint group entity
    ...
    +   * @return self
    +   *   The called breakpoint group entity
    ...
    +   * @return self
    +   *   The called breakpoint group entity
    ...
    +   * @return self
    +   *   The called breakpoint group entity
    

    @return $this

  2. +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php
    @@ -25,6 +25,99 @@
    +  public function setLabel($label);
    

    Why is there no getLabel() method here?

LinL’s picture

Status: Needs review » Needs work

The last submitted patch, 51: expand-breakpointgroup-with-methods-2030587-51.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 55: expand-breakpointgroup-with-methods-2030587-55.patch, failed testing.

amitgoyal’s picture

Status: Needs work » Needs review
FileSize
14.78 KB
498 bytes

Please review updated patch for fixes in #55.

RainbowArray’s picture

In all likelihood this issue is going to not be relevant if we get #2271529: Move breakpoint settings to theme and module *.breakpoints.yml files at root level done.

filijonka’s picture

Issue summary: View changes
Status: Needs review » Postponed

postponing this until #2271529: Move breakpoint settings to theme and module *.breakpoints.yml files at root level. If that is done we shall close this issue.

sorry @mdrummond and everyone else I forgott I was supposed to do this long time ago

attiks’s picture

Status: Postponed » Closed (won't fix)