Currently there's lots of code that checks whether a field exists by calling $entity->getPropertyDefinition(). Firstly, there's some terminology confusion around "property definition" vs. "field definition". #2047229: Make use of classes for entity field and data definitions might help resolve some of that. But secondly, module code shouldn't need to deal with the concept of a definition at all if all it wants to do is know whether the field exists.
So, this patch adds a hasField() method.
Comment | File | Size | Author |
---|---|---|---|
entity-has-field.patch | 10.15 KB | effulgentsia | |
Comments
Comment #1
larowlanYes, comment module could use this, as seen by the patch :)
Comment #2
smiletrl CreditAttribution: smiletrl commentedMakes sense..
Comment #3
jibranAwesome patch is green.
Before the patch
After the patch
core/lib/Drupal/Core/Entity/ContentEntityBase.php:370
is introduced by the patch I think we can fix the rest.Comment #4
effulgentsia CreditAttribution: effulgentsia commentedThe rest either deal with typed data objects that aren't entities, or else need the returned definition.
Comment #5
jibranok RTBC then.
Comment #6
fagoThat's a great addition and makes code better readable, +1!
Comment #7
Wim LeersNice! :)
Comment #8
webchickThis seems pretty harmless, and is a nice clean-up of code.
Committed and pushed to 8.x. Thanks!
Needs a change notice.
Comment #9
BerdirAdded a snippet to https://drupal.org/node/1806650.