ImageStyle class variables should not be accessed directly. Functions should be use to access the variable. For instance use getDescription() and setDescription($description) for the protected class variable description. For a boolean variable the getter function becomes isVariableName(). In object-oriented programming this is called encapsulation.

Remaining tasks

  • Update the class variables and make them protected.
  • Create getters and setters for frequently used get and set functionality.
  • Update drupal to use the getters and setters instead of accessing variables directly.
  • There are no tests required because the added functions are only getters and setters.

For more info over what should be done see the issue summary of #2016679: Expand Entity Type interfaces to provide methods, protect the properties.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because properties should not be public, API methods should not be allowed to be sidestepped.
Issue priority Major because this meta goes across the entire system. But each child will be a normal bug.
Prioritized changes Prioritized since it is a bug and it reduces fragility.
Disruption Somewhat disruptive for core as well as contributed and custom modules:
  • BC break for anything using the public properties: code will need to convert to the methods
  • BC break for anything (mis)using properties that should not really be public: will require minor refactoring
  • BC break for alternate implementations of a given entity interface (rare/probably nonexistent): they will need to implement the new methods

But impact will be greater than the disruption, so it is allowed in the beta.

Comments

daffie’s picture

I would like to get this fixed. So I will do a good review for posted patches.

daffie’s picture

Issue summary: View changes

The class variables $name and $label need to become protected.
You can use the functions id() as a getter function for the name variable and label() as a getter function for the variable label.

sharique’s picture

Status: Active » Needs review
StatusFileSize
new1.77 KB

Here is the patch. Please review.

Status: Needs review » Needs work

The last submitted patch, 3: 2384535-make-class-varibales-protected-imagestyle-3.patch, failed testing.

daffie’s picture

+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -392,6 +392,21 @@ public function setName($name) {
+   * {@inheritdoc}
+   */
+  public function getLabel() {
+    return $this->get('label');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setLabel($label) {
+    $this->set('label', $label);
+    return $this;
+  }

The function getLabel() is not necessary. There is a build in function label().
The function setLabel() will probably not be used. Maybe only in testing. You can remove them and use set('label', $value).

fernando_calsa’s picture

Assigned: Unassigned » fernando_calsa

I go to work in this issue

fernando_calsa’s picture

Assigned: fernando_calsa » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.17 KB
new658 bytes

As daffie comments in #5 I've removed getLavel() and setLabel()

Status: Needs review » Needs work

The last submitted patch, 7: 2384535-make-class-variables-protected-imagestyle-7.patch, failed testing.

areke’s picture

Status: Needs work » Needs review
StatusFileSize
new1014 bytes

Status: Needs review » Needs work

The last submitted patch, 9: 2384535-9.patch, failed testing.

daffie’s picture

The reason that your patch failed testing is that outside the NodeType class the class variables are no longer accessible. And it will result in an error. Use the methods id() and label() to fix this. If you need the set a variable use set('name', $value) or set('label', $value).

+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -99,6 +99,22 @@ public function id() {
+  public function label() {
+    return $this->get('label');
+  }

This function is inherited from the Entity class. So it can be removed.

+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -99,6 +99,22 @@ public function id() {
+  public function setLabel($label) {
+    $this->set('label', $label);
+    return $this;
+  }

This function is not used. You can remove it and use set('label', $value).

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new578 bytes

Status: Needs review » Needs work

The last submitted patch, 12: 2384535-12.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB
daffie’s picture

Status: Needs review » Needs work
+++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php
@@ -246,7 +246,7 @@ function testStyle() {
-        '%style' => $style->label,
+        '%style' => $style->get('label'),

Your solution also works, but there is a build in function label() that does the same. And that is the function that other developers expect.

areke’s picture

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

Status: Needs review » Needs work

The last submitted patch, 16: 2384535-16.patch, failed testing.

Status: Needs work » Needs review

daffie queued 16: 2384535-16.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 16: 2384535-16.patch, failed testing.

rpayanm’s picture

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

Status: Needs review » Needs work

The last submitted patch, 20: 2384535-18.patch, failed testing.

daffie queued 16: 2384535-16.patch for re-testing.

The last submitted patch, 16: 2384535-16.patch, failed testing.

Status: Needs work » Needs review

daffie queued 20: 2384535-18.patch for re-testing.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All the class variables are protected.
There are already getter functions available, so no need for new ones.
The test-server give it green.
It all looks good to me, so for me it is RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 4acf770 and pushed to 8.0.x. Thanks!

  • alexpott committed 4acf770 on 8.0.x
    Issue #2384535 by rpayanm, fernando_calsa, areke, Sharique: Make the...

Status: Fixed » Closed (fixed)

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