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.
After #2047229: Make use of classes for entity field and data definitions is in, all EntityType's base fields definitions should be converted to object.
Remaining Taks:
- Convert base field definitions from array to object for EntityType 'user', 'node', etc. Take 'Term' for converting reference.
- Remove
FieldDefinition::createFromOldStyleDefinition
andDataDefinition::createFromOldStyleDefinition
. - Remove array support for base field definitions at hook_entity_field_info()/hook_entity_field_info_alter(), e.g., content_translation_entity_field_info_alter(). Update associated hook docu.
- Remove left 'list_class', but use 'list_type' instead.
- Update remaining array access to definition objects to use methods.
Comment | File | Size | Author |
---|---|---|---|
#35 | interdiff.txt | 4.11 KB | amateescu |
#35 | 2112239-35.patch | 152.56 KB | amateescu |
Comments
Comment #1
BerdirAdd
- Update remaining array access to definition objects to use methods
to that list :)
This places might not be obvious at first, but where for example talking about all $this->defintion within field item classes. I'm sure there are places where we still use it as an array.
Comment #1.0
BerdirAdd remaining 'list_type'
Comment #2
smiletrl CreditAttribution: smiletrl commentedadded.
Comment #2.0
smiletrl CreditAttribution: smiletrl commentedUpdated issue summary.
Comment #3
plachfollowing
Comment #4
yched CreditAttribution: yched commentedLooks like we can unpostpone now ?
Comment #5
amateescu CreditAttribution: amateescu commentedLooks like we even have a patch now! Quite a tedious one if I may say, so please don't change this again :)
A quick observation after all this is that we need a Timestamp field, or the existing Date field needs to comunicate its purpose better.
Comment #7
amateescu CreditAttribution: amateescu commentedNo, it did not take the whole day to write this, why would anyone think that?!
Comment #9
amateescu CreditAttribution: amateescu commentedAnd not even half a night to investigate some crazy list behaviors..
One problem after removing createFromOldStyleDefinition() is that (for a FieldDefinition) in
TypedDataManager::getPropertyInstance()
,$definition['type']
was 'field_item:bla' before and now$definition->getDataType()
is just 'list'.Comment #11
amateescu CreditAttribution: amateescu commentedAfter some hours of sleep and with a clear head, I figured this:
Since the data type of a ListDefinition and FieldDefinition is always 'list', the only thing we can do in
TypedDataManager::getPropertyInstance()
is to add another element to the "cache key", which is the data type of the item definition, like so:Comment #13
amateescu CreditAttribution: amateescu commentedAfter talking a bit with @fago in IRC, it seems that we want to use both the data type and the settings of the item definition, if the root definition is a list. Also added a few helper methods: getSetting(), setSetting() and getConstraint().
Looking at the TypedConfig stuff.. it's probably best if we bring back ArrayAccess just for that and convert everything related to TypedConfig in a followup, otherwise this can easily go over 200K :(
Comment #15
amateescu CreditAttribution: amateescu commentedSome brown paper bag fixes, but that CommentFieldName stuff is a tough nut..
Comment #16
amateescu CreditAttribution: amateescu commentedThis seems to work.
Comment #19
amateescu CreditAttribution: amateescu commentedGetting there :)
Comment #22
fagogetPropertyInstance() code looks good, I'd suggest adding the item definition settings to the $key also though. Properties of an item could vary by its settings.
Interesting - is that the approach do it now? Do you have a pointer to an issue discussing it, or guidelines? It seems to be missing from https://drupal.org/node/1354#types.
I don't think we should do that, when you do YourClass::create() type-hinting should be aware of everything in YourClass - not only about the stuff in the interface.
Debugging code - config-type definitions should be the only array-definitions flying around here. Cleaning that up is not trivial and should probably be done over at #1928868: Typed config incorrectly implements Typed Data interfaces.
If we could move it to work with objects based on array access here, that would be a good first step imho. Else, we cannot start type-hinting on DataDefinitionInterface.
Imo this shows nicely how class based definitions can help simplifying things :-)
hm. We'll be using PHP 5.4 so we could do $this->definition->getSettings()['target_type'] in future?
But we cannot do it yet, so maybe we could add a getSetting() just for now and note and will be removed just right now + search/replace it later on?
hm, we've got several issues here.
a) It right now does not return a constraint object, but the array-based constraint definition which is later on turned to constraint objects.
Then, a return value of NULL does not necessarily mean the array-key is not set, i.e. the constraint could be set with NULL for $options what works -- see Constraint::__construct().
Moving to constraint objects as return value would make the read/write API a bit different. We could go with write by objects as well, but creating constraint objects is no nice OO API as constraint objects require *complete* constraint options for construction, or they throw exceptions. Thus, creation probably has to stay with plugin-id + options array.
good questions, but out of scope here. Maybe let's move all of this in separate issue?
In regard to the timestamp fields, I've recently created #2145103: Provide non-configurable field types for entity created, changed and timestamp fields. We probably want to add a general timestamp field, plus two special ones for created and changed dates.
should probably use setSetting()
hm, seeing this I think we should move ConfigFieldItemList::getConstraints() content here. Separate issue though.
Comment #23
amateescu CreditAttribution: amateescu commentedIt's already added to the key because I'm switching the whole thing to an ItemDefinition if the root definition is a list:
getSetting()
method in DataDefinition. I chose not to use it here because another setting is used below ('target_bundles'), so we can save a function call.getConstraints()
, fixed both of them.Comment #25
amateescu CreditAttribution: amateescu commentedComment #27
fago23: 2112239-23.patch queued for re-testing.
Comment #28
amateescu CreditAttribution: amateescu commented25: 2112239-25.patch queued for re-testing.
Comment #30
amateescu CreditAttribution: amateescu commentedYay for a green patch, finally!
Comment #31
amateescu CreditAttribution: amateescu commentedRerolled after #1988612: Apply formatters and widgets to rendered entity base fields, starting with node.title.
Comment #33
amateescu CreditAttribution: amateescu commentedThe node title field doesn't need its specific constraint anymore, it's added automatically by the field type now.
Comment #34
fagook, reviewed this monster (and dreditor at it once, grrr - so going without now)
Patch does not apply any more (ValidReferenceConstraintValidator).
The @todo seems to be lost.
Imo, unsure todos - aka todos that are questions - shouldn't be in the code. We should create issues for them, then either re-phrase them to be absolute (if clear), or just leave them out in favor of the issue.
Two times again.
Again.
Again.
Looks like this got lost ;-)
Comment #35
amateescu CreditAttribution: amateescu commentedAll those TODOs were formulated as questions because I didn't know if we want to pursue them in this issue or in followups. Now that we decided for followups, I opened issues for each one:
#2149841: The 'aggregator_feed' entity type doesn't have a UUID field
#2149845: Convert the description field of the 'aggregator_item' entity to a text field
#2149851: Remove todo about GUID field on the 'aggregator_item' entity and add UUID field
#2149859: Convert the 'field_id' base field on comment entities to an entity reference field
#2149877: The 'filesize' base field of field entities is a boolean?
Edit: fixed typo
Comment #36
yched CreditAttribution: yched commentedJust a side question: I never really understood the static::$propertyDefinitions pattern used in getPropertyDefinitions() (or I was explained and forgot)
Is it still needed ? It's esp. weird to use a static here since the actual content can depend on $this->definition ?
Comment #37
fagoad #35: I see, thanks!
small typo - aa
Anyway, this is ready to go, so let's move on before it doesn't apply anymore.
ad #36: When you have X instances of an entity, the same field item with the same definition will be instantiated X times. For that we want/need to avoid having X instances of the same property definitions. Update: But yes, that static has to be keyed by any definition settings that might apply, e.g. ER fields do so.
Comment #38
yched CreditAttribution: yched commented@fago / getPropertyDefinitions() / static::$propertyDefinitions:
Right, makes sense.
I opened #2150555: Change field types to define their property definitions statically for what we talked about in Vienna, with additional considerations on this static:: pattern.
Comment #39
chx CreditAttribution: chx commentedComment #40
catchThis looks great. Removes a bc layer and with it lots of cruft.
This hunk made me grin:
;)
Committed/pushed to 8.x!
I think there's already a change notice, but we might want to add that the bc layer has been removed?
Comment #41
Berdir#2047229: Make use of classes for entity field and data definitions didn't have a change notice before this landed, and that BC layer only existed for a short time and wasn't mentioned, I don't think we need to do something here.
Comment #42
mradcliffeI think this either needs a change notification or the previous change notification regarding data definitions needs to be updated. There's also a handbook page about it too.
- Change notice: http://drupal.org/node/2064123
- Documentation: http://drupal.org/node/2112677
Comment #43
mradcliffeI updated the existing change record and here is a draft of a new change record.
--
Title: Property definitions are now objects
ComplexDataInterface::getPropertyDefinitions() now returns an array of DataDefinition objects. This effects modules implementing FieldType plugins and TypedData. This changes the API referred to in change notice Field types are now plugins, which has been updated as well. This notice
Previously in Drupal 8
Changed to in Drupal 8
Comment #44
BerdirOh, completely forgot about that part, sorry. I also updated a bunch of documentation pages like https://drupal.org/node/2128865 and https://drupal.org/node/2112677, there are probably more of those still.
The change notice looks good, as we create one anyway, you might want to mention that this affects base fields as well and point to https://drupal.org/node/1806650 for details on that.
Also, make sure to reference both this issue and #2047229: Make use of classes for entity field and data definitions as the related issues.
Then set this to fixed again :)
Comment #45
amateescu CreditAttribution: amateescu commentedI don't think we've done this kind of HEAD to HEAD change notices before..
In case we want to make an exception here (I don't see why though), we might want to wait for #2002134: Move TypedData metadata introspection from data objects to definition objects which will also change the way of declaring property definitions a bit (removes the ugly / sometimes confusing statics).
Comment #46
BerdirI've done a few of those, I think it's ok. It's meant as a notice for people that are already starting to upgrade their modules and tell them where to look for details.
For example, we already have *two* detailed tutorials on how to create/upgrade a field type implementation on d.o, one of those coming from a blog post that should be updated as well now.
Comment #47
amateescu CreditAttribution: amateescu commentedOkay then, change notice it is :)
Comment #48
klonos...coming from #2039607: Change node type field to an entity reference
Comment #49
xjmTagging "Missing change record", as completing the change record updates here blocks a beta: #2083415: [META] Write up all outstanding change notices before release
Comment #50
BerdirThis was only kept open for an HEAD to HEAD change notice which will change once more in #2002134: Move TypedData metadata introspection from data objects to definition objects.
I think it's kind of pointless to do such a change notice 2 month after it happened and (hopefully) shortly before it changes again, so setting to fixed again. Make sure to follow the referenced issue to get notified when the upcoming change to the getPropertyDefinitions() lands. I can guarantee that you will like that change/simplification there and then this area will hopefully stabilize.