EntityForm has a magic setter and getter to take care of triggering a deprecation error, eg:

  public function __get($name) {
    // Removing core's usage of ::setEntityManager means that this deprecated
    // service wont be set. We provide it here for backwards compatibility.
    if ($name === 'entityManager') {
      @trigger_error('EntityForm::entityManager is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use EntityForm::entityTypeManager instead. See https://www.drupal.org/node/2549139', E_USER_DEPRECATED);
      return $this->privateEntityManager ?: \Drupal::entityManager();
    }
  }

However, this does nothing when $name is not entityManager. So any form class that does $this->foo = 'bar' without having declared $foo as a class property will suddenly find that setting the value has no effect.

Credit to @aalin to figuring this one at #3093329: $moduleEntityData error in ComponentSectionForm.php.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

joachim’s picture

Issue summary: View changes
joachim’s picture

Issue summary: View changes
joelpittet’s picture

Status: Active » Needs review
Related issues: +#3097934: Fatal error on admin page
FileSize
1.64 KB

How about something like this?

joelpittet’s picture

joachim’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityForm.php
@@ -68,6 +80,9 @@ public function __get($name) {
+      return $this->privateData[$name];

I don't understand we need the intermediary of the privateData array.

Can we not just do $this->{$name}?

Berdir’s picture

Status: Needs review » Needs work

Yes, I think we can just check for/set $this->$name. There's also a typo to fix in __set(): "This *is* property".

neel24’s picture

Status: Needs work » Needs review
FileSize
1.63 KB
764 bytes

I made some changes based on comment #7. Attaching an interdiff as well.

agrochal’s picture

Status: Needs review » Needs work

In the "__set" function, there's still $this->privateData[$name] = value;. I think we can also remove declaration of this array private $privateData = [];.

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
1.45 KB

Changes based on comment #4 , #7 and #9. Attaching an interdiff as well.

joachim’s picture

Status: Needs review » Needs work

Looking good, just the comment needs work:

+++ b/web/core/lib/Drupal/Core/Entity/EntityForm.php
@@ -82,6 +85,11 @@ public function __set($name, $value) {
+      // This is property exists because this magic method breaks when

This sentence doesn't read properly.

Madhura BK’s picture

Assigned: Unassigned » Madhura BK
AkashKumar07’s picture

Assigned: Madhura BK » Unassigned
Status: Needs work » Needs review
FileSize
1.14 KB
1.41 KB

Removed declaration of

 array private $privateData = [];
Hardik_Patel_12’s picture

Status: Needs review » Needs work

@AkashkumarOSL ,

Kindly look comment #11 and #10 , we need to change comments only now in set method.

neel24’s picture

Status: Needs work » Needs review
FileSize
1.16 KB

I've created a new patch based on the necessary changes.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

Thanks!

AkashKumar07’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.16 KB
997 bytes

Please review this patch.

Hardik_Patel_12’s picture

Status: Needs review » Reviewed & tested by the community

Patch written in #15 looks great to me.
@AkashkumarOSL , changes done in #17's patch is not required kindly look patch written in #15.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Yep #17 is an incorrect bugfix. #15 looks like the correct fix but #17 shows that we don't have any test coverage. We should have that.

alexpott’s picture

Status: Needs work » Needs review
FileSize
1020 bytes
719 bytes
1.87 KB

Actually there was a bug in #15 too. Here's a test and fix.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityForm.php
@@ -68,6 +68,9 @@ public function __get($name) {
+    elseif (isset($this->$name)) {
+      return $this->$name;
+    }

This is not necessary.

The last submitted patch, 20: 3094913-21.test-only.patch, failed testing. View results

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

Note: This BC layer was already removed in 9.0.x, so this does not need to be committed there.

  • catch committed 7d7c475 on 8.9.x
    Issue #3094913 by alexpott, AkashkumarOSL, neel24, Hardik_Patel_12,...

  • catch committed 5521e96 on 8.8.x
    Issue #3094913 by alexpott, AkashkumarOSL, neel24, Hardik_Patel_12,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7d7c475 and pushed to 8.9.x, then cherry-picked to 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

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