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.
ConfigEntityBase isNew() method checks that id() returns '' or NULL
final public function isNew() {
// Configuration entity IDs are strings, and '0' is a valid ID.
return !empty($this->enforceIsNew) || $this->id() === NULL || $this->id() === '';
}
but id() always returns a value so createDuplicate()
is broken too
Comment | File | Size | Author |
---|---|---|---|
#5 | config_entity-isNew-1970110-5.patch | 621 bytes | yched |
Comments
Comment #1
andypostTaggin
Comment #2
larowlanTagging
Comment #3
yched CreditAttribution: yched commentedHmm.
According to ConfigEntityBase, isnew() is FALSE the moment the $config_entity has a non empty id.
(or between entity_create() and save(), when enforceIsNew is TRUE)
That seems wrong to me ?
Entity does :
That seems very much tied to a pre-D8 model where "a $node is considered new before it got saved and received a serial id in the process".
If so, I'd say the equivalent of this for ConfigEntities is the presence of a UUID, not an id, because ConfigEntities will always have an id (a machine name) ?
Bumping to the config system for feedback.
Comment #4
andypostIt was introduced in #1813832: Entity wrongly checks existence of ID in isNew() method
Comment #5
yched CreditAttribution: yched commentedDiscussed this with @Berdir and @fago.
ConfigStorageController::create() calls $entity->enforceIsNew() already.
ConfigEntityBase::isNew() should be based only on the enforceIsNew flag.
Comment #7
tim.plunkett#5: config_entity-isNew-1970110-5.patch queued for re-testing.
Comment #8
BerdirMakes sense, checking Id for config entities has no meaning as it's always manually assigned.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks.