Fix ContentEntityBase::__get() to not return by reference

Created on 23 April 2013, over 11 years ago
Updated 10 April 2023, over 1 year ago

I am not sure what to report and how to do it. This is not a rage issue. This is factual: I am writing a patch and I found that I somehow broke the default values of the instance. It's in the config YAML but it doesn't go as far as the widget.

Now. I had my share of Drupal (I even wrote small parts of it ;) ) and PHP and stuff and although I had my grievances with other parts of D8 but eventually I found my way around (even if I really didn't like it). But this, here's absolutely no way to figure out how a piece of data gets from storage to screen (eventually I figured that the default value is coming from field_entity_create).

For example, watch this beauty from field storage:

$entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;

If you vaguely know how the entity-field API now works, you'd expect this to involve magic setters. Wrong. It uses the magic getters which return a reference (!) and so the equal sign can write directly into that... Note that EntityNG also has &__get().

This needs a very, very serious documentation effort to make it viable.

webchick asked to make this actionable. Well:

  1. How does the system determine what properties an entity object has? Like, $node.
  2. How do those properties get populated?
  3. Given the amount of magic, any caveats retrieving those properties
📌 Task
Status

Needs work

Version

9.5

Component
Entity 

Last updated about 1 hour ago

Created by

🇨🇦Canada chx

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024