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

Support from Acquia helps fund testing for Drupal Acquia logo

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
daffie’s picture

Component: node system » filter.module
daffie’s picture

Issue summary: View changes

The class variables $format, $name and $weight need to become protected.

Sharique’s picture

Status: Active » Needs review
FileSize
3.19 KB

I've also changed the name for variables, which was specified in todo. Do we need setId function? I think we need it.

Status: Needs review » Needs work

The last submitted patch, 5: 2384487-make-class-variables-protected-filterformat-3.patch, failed testing.

daffie’s picture

I would not rename the class variables. I know there is a @todo is the code. The problem is that renaming a variable will result in a lot of changes. And I have the idea that that will not be allowed (beta changes).

+++ b/core/modules/filter/src/Entity/FilterFormat.php
@@ -428,4 +424,34 @@ protected function calculatePluginDependencies(PluginInspectionInterface $instan
+  /**
+   * {@inheritdoc}
+   */
+  public function getLabel() {
+    return $this->get('label');
+  }
+

This function is not necessary. You can use the build in function label().

+++ b/core/modules/filter/src/Entity/FilterFormat.php
@@ -428,4 +424,34 @@ protected function calculatePluginDependencies(PluginInspectionInterface $instan
+  /**
+   * {@inheritdoc}
+   */
+  public function setLabel($label) {
+    $this->set('label', $label);
+    return $this;
+  }
...
+  /**
+   * {@inheritdoc}
+   */
+  public function setWeight($weight) {
+    $this->set('weight', $weight);
+    return $this;
+  }

These function are probably not used. Maybe only in testing. You can remove them and use set('name', $value) and set('weight', $value)

rpayanm’s picture

Status: Needs work » Needs review
FileSize
970 bytes

Status: Needs review » Needs work

The last submitted patch, 8: 2384487-8.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
9.14 KB

Round 1

Status: Needs review » Needs work

The last submitted patch, 10: 2384487-10.patch, failed testing.

daffie’s picture

+++ b/core/modules/filter/filter.module
@@ -246,7 +246,7 @@ function filter_default_format(AccountInterface $account = NULL) {
-  return $format->format;
+  return $format->get('format');

Use the function id() for this instead of get('format').

rpayanm’s picture

Status: Needs work » Needs review
FileSize
16.16 KB

Round 2

rpayanm’s picture

Assigned: Unassigned » rpayanm

@daffie ohhh thank you.

rpayanm’s picture

FileSize
15.93 KB

The last submitted patch, 13: 2384487-12.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: 2384487-12.patch, failed testing.

Status: Needs work » Needs review

daffie queued 15: 2384487-12.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: 2384487-12.patch, failed testing.

Status: Needs work » Needs review

rpayanm queued 15: 2384487-12.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: 2384487-12.patch, failed testing.

Status: Needs work » Needs review

daffie queued 15: 2384487-12.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: 2384487-12.patch, failed testing.

Status: Needs work » Needs review

daffie queued 15: 2384487-12.patch for re-testing.

rpayanm’s picture

ohh god! appear that testbot it's on trouble :(

Status: Needs review » Needs work

The last submitted patch, 15: 2384487-12.patch, failed testing.

rpayanm’s picture

Title: Make the class variables protected for Filterformat » Make the class variables protected for FilterFormat
Assigned: rpayanm » Unassigned
Status: Needs work » Needs review
FileSize
18.65 KB

No rest!

Status: Needs review » Needs work

The last submitted patch, 27: 2384487-27.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
21.41 KB

Status: Needs review » Needs work

The last submitted patch, 29: 2384487-29.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
22.96 KB

Status: Needs review » Needs work

The last submitted patch, 31: 2384487-31.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
23.65 KB

Status: Needs review » Needs work

The last submitted patch, 33: 2384487-33.patch, failed testing.

areke’s picture

Status: Needs work » Needs review
FileSize
24.28 KB

Status: Needs review » Needs work

The last submitted patch, 35: 2384487-35.patch, failed testing.

Status: Needs work » Needs review

daffie queued 35: 2384487-35.patch for re-testing.

daffie’s picture

Status: Needs review » Needs work
+++ b/core/modules/filter/src/Tests/FilterAdminTest.php
@@ -261,7 +261,7 @@ function testFilterAdmin() {
+    $this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->get('name'))), 'Full HTML format successfully updated.');

@@ -319,7 +319,7 @@ function testFilterAdmin() {
+    $this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->get('name'))), 'Full HTML format successfully reverted.');

+++ b/core/modules/filter/src/Tests/FilterCrudTest.php
@@ -70,21 +70,21 @@ function testTextFormatCrud() {
+    $t_args = array('%format' => $format->get('name'));
...
+    $this->assertEqual($filter_format->get('name'), $format->get('name'), format_string('filter_format_load: Proper title for text format %format.', $t_args));

Use label() instead of get('name'). In the annotation of the FilterFormat class is the variable $name defined as being the label. And the label has its own getter function called label().

After this change it is RTBC for me. Good work ;-)

rpayanm’s picture

Status: Needs work » Needs review
FileSize
3.21 KB
24.26 KB
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

Issue tags: +Needs reroll

Patch needs to be rerolled... it looks good though.

daffie queued 39: 2384487-39.patch for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 39: 2384487-39.patch, failed testing.

rpayanm’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
24.28 KB

Rerolled :)

daffie’s picture

The file core/modules/text/src/Tests/TextFieldTest.php was updated. So a reroll was necessary. Also for me RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/filter/src/Tests/FilterAdminTest.php
@@ -261,7 +261,7 @@ function testFilterAdmin() {
+    $this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->get('name'))), 'Full HTML format successfully updated.');

@@ -319,7 +319,7 @@ function testFilterAdmin() {
+    $this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->get('name'))), 'Full HTML format successfully reverted.');

+++ b/core/modules/filter/src/Tests/FilterCrudTest.php
@@ -70,21 +70,21 @@ function testTextFormatCrud() {
+    $t_args = array('%format' => $format->get('name'));
...
+    $this->assertEqual($filter_format->get('name'), $format->get('name'), format_string('filter_format_load: Proper title for text format %format.', $t_args));

Let's use label() instead.

daffie’s picture

Status: Needs work » Needs review
FileSize
24.23 KB

I thought that the get('name') was replaced by label() in the past. Somehow it got back in. :-(

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Double checked it. The file core/modules/text/src/Tests/TextFieldTest.php was updated. So a reroll was necessary. All the get('name') are gone again.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3ec6348 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation for to the issue summary.

  • alexpott committed 3ec6348 on 8.0.x
    Issue #2384487 by rpayanm, daffie, Sharique, areke: Make the class...
Wim Leers’s picture

Status: Fixed » Active

This broke HEAD.

EditorImageDialog still contains:

$editor = editor_load($filter_format->format);

And because format is now a protected property, a fatal error is thrown.

I don't know what's preferred: a revert + reroll, or a new issue to fix it.

daffie’s picture

@Wim Leers: How much problems is it giving now?

We need to fix this and add a test to make sure it does not happen again.

daffie’s picture

Same problem in core/modules/editor/src/Plugin/InPlaceEditor/Editor.php (line 39).

The bug from commend #51 is in file core/modules/editor/src/Form/EditorImageDialog.php (line 51).

Wim Leers’s picture

daffie: it's making it impossible to upload or edit images via CKEditor. So: a big problem.

daffie’s picture

Status: Active » Needs review
FileSize
1.6 KB

Quick fix without new tests.

daffie’s picture

FileSize
701 bytes

It is a bit confusing to me when ->format is from the filter_format entity en when it is the property of a text field. So also a patch to only quick fix the bug reported by Win Leers.

The last submitted patch, 55: 2384487-55.patch, failed testing.

Wim Leers’s picture

#55 is wrong, #56 is correct. The difference is quite big: just looking for ->format is not enough. The first hunk in #55 is getting the "format" property on a FilterFormat entity, the second is getting the "format" property on a TextItem.

But #56 is never going to be committed here. It needs to be put in its own issue. We no longer do "follow-up commits".

That's why I wrote:

I don't know what's preferred: a revert + reroll, or a new issue to fix it.

daffie’s picture

My idea was that we do it as a followup in this issue. It seams that that is not allowed, so here is the followup: #2389381: Impossible to add images in WYSIWYG including in-place editing due to fatal error

daffie’s picture

Status: Needs review » Closed (fixed)

The issue has been fixed and the followup issue has also been fixed.

YesCT’s picture

I'm not sure why this was opened instead of using #2030641: Expand FilterFormat with methods but I closed that as a duplicate. It is a bit sad that the people who worked on that were not included in this.

YesCT’s picture