Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment #N
Problem/Motivation
In ConfigStorageController::save(), the first check is
$id = $entity->id();
if ($id === NULL || $id === '') {
throw new EntityMalformedException('The entity does not have an ID.');
}
But then after some other code loading the CMI object directly, we have this
// Build an ID if none is set.
if (!isset($entity->{$this->idKey})) {
$entity->{$this->idKey} = $entity->id();
}
This should be completely unnecessary, and has the side effect of forcing the ID key to be public.
Proposed resolution
Remove this line, and change the ID property on at least one entity to protected.
Remaining tasks
N/A
User interface changes
N/A
API changes
When the id() method is overridden to use something other than $entity->{$idKey}
, the id() method must be used in toArray() so that it is set properly.
Comment | File | Size | Author |
---|---|---|---|
#19 | configentity-2224833-19.patch | 10.25 KB | tim.plunkett |
#6 | configentity-2224833-6.patch | 16.1 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettIf a compound entity ID is used, then it cannot use $entity->get('id') or equivalent in toArray(), it must use id().
A follow-up to #2016679: Expand Entity Type interfaces to provide methods, protect the properties should be to make all config entity properties protected, and we can improve ConfigEntityBase::toArray() accordingly.
The only difference between A and B is that B makes $id protected for EntityDisplayBase
Comment #4
tim.plunkettFieldInstanceConfig
__wakeup() -> toArray() -> id() -> $this->field->name -> BOOM
Can be $this->field_name
Comment #6
tim.plunkettNot so quick anymore.
Comment #7
tim.plunkettThis one was done as an example. Should I go through the rest of the config entities and make this change? If not, this patch should be good to go.
Comment #8
tim.plunkettGetting this issue in now will let us change each entity type in their respective subissue in #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
I think we should tackle those individually and get this in as-is.
Comment #9
tim.plunkettPer #8, I'm stripping this down to the absolute minimum changes.
Comment #11
tim.plunkettRestoring the image changes from #6 :(
Comment #16
tim.plunkettUgh, still cut out too much.
Comment #17
tim.plunkettOkay forget this. I remember adding those changes for a reason, and I guess this was why.
#6 needs review.
Comment #18
tim.plunkettOkay one more try for a stripped down version.
Comment #19
tim.plunkettgit 3-way merge++
Comment #20
tim.plunkettComment #21
dawehnerThis seems to be perfect, I can't see something horrible
Comment #22
webchickCommitted and pushed to 8.x. Thanks!