Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
entity system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Jan 2014 at 22:11 UTC
Updated:
15 Sep 2015 at 13:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
damiankloip commentedComment #2
tim.plunkettI'm not too concerned about the public properties, but this does solve that.
I wonder if this will really be better in the end though.
These shouldn't have quotes around them.
I mainly worry about entity type authors, as this makes the annotation keys even harder to find.
This kinda sucks.
This is a wash, either way.
I wonder if this will present a problem (isset vs empty)? Hopefully not.
Comment #3
damiankloip commentedI'm not sure how this makes them harder to find? Having a documented array structure like this is more akin to the annotation. Do you not think the mapping (in people's minds) from annotation keys to class properties is slightly more tedious? It is definitely not obviously that these properties map to that, unless you understand what's going on internally.
Yeah, that does suck a bit. This was a pretty quick implementation but I am ok with doing something like that. It's an internal implementation after all. Any ideas on how to make that better? I could look at doing something using NestedArray? If not, I can certainly live with that. I've seen worse things...
I think not, everything seems ok at the moment. Well, let's hope that's the case anyway :)
Comment #4
eclipsegc commentedSo, this issue and #2169853: EntityType Annotation does not extend AnnotationBase are sort of similar and also sort of opposed.
One of the observations I've made here is that if the EntityType annotation moves to AnnotationBase, we should probably enumerate the properties common to all Entity Types on it. I'm doing some very simple filtering of the values passed to the annotation and putting any that are not also properties into an array together. With regard to how this actually affects the Annotation, I fell it's the best of all worlds since we can continue to add non-property elements to the annotation to extend the API in contrib, but we also set a standard for every required property.
The flip side to all of this is 2 fold:
This being the first discovery methodology to leverage class instances as definitions puts us in unexplored territory (at least within Drupal 8) and I want to keep an open mind about what the implementation could/should do. Still that being said, moving to a pure array definition of the "properties" feels like a drastic step backwards imo, and I'd prefer we not do that. I'm not really making an argument with regard to the specifics of the "entity system" itself, I'm speaking more in terms of just plugins in general.
Eclipse
Comment #5
filijonka commentedFirst of all I'm a lil bit concerned that we OOP speaking think that it's ok to add properties that are not defined by the class, if you as user wanna add properties to a class that isn't defined, extend it and add your own properties and functions for it if needed. Otherwise it's will be hard to say what kind of object is this.
So in my opionon the current solution is not done correctly by letting any properties be added.
IF this is still something that is wanted it's clearly not good as it is since the properties not defined by class will be public but the solution to add a property that will hold any user added property in a associativ array.
Comment #6
dawehnerIMHO not storing public stuff is still the right thing to do.
Comment #7
dawehnerEspecially because it also breaks some of the internal PHP optimizations: #2531564: Fix leaky and brittle container serialization solution
Comment #8
tim.plunkettWhat public stuff? It's all protected. What is broken here?
Comment #9
damiankloip commentedWhat about when contrib gets involved, any key that is not defined will just be public properties on the entity type. E.g. I am looking at a contrib module D8 port of OG, they have not touched it for a while, and still have a 'module' key in the annotation. So that's now a public property on the entity types.
It's just not broken in core because core is careful about what is implemented in the annotation.
Comment #10
damiankloip commentedSpecifically this in the constructor:
Comment #11
damiankloip commentedSpoke to Tim, we could just have something like this. Might want a new Exception or something, and maybe a better message!
Comment #13
tim.plunkettHope we didn't care about BaseFieldOverrideStorage too much...
Comment #14
tim.plunkettI love checking DrupalCI for live results.
Fixing EntityTestUpdate for #2100343: Remove 'fieldable' key in entity definitions in favour of 'field_ui_base_route'.
Comment #16
tim.plunkett<3
I guess I'll open a test-only issue to finish this... Next patch
Comment #17
tim.plunkettThe docs on content_translation_entity_type_alter() *tell* you to break this by adding arbitrary keys. :(
Comment #18
tim.plunkettHere is an example of a fix for that (and an example for contrib). The obvious problem here is that only one module can set entity_type_class...
Comment #19
tim.plunkettComment #20
berdirCan be removed, set automatically?
Other than that, this approach doesn't make sense to me. The class approach doesn't work IMHO, that allows to set exactly one additional property. It's quite common for modules to extend this, we just have the luxury in core to actually be able to define those on the annotation class. Contrib doesn't. common_reference_target is entity_reference specific and I know that entity_reference_revisions adds a parallel property for that, field_ui_base_route is obviously field_ui specific, permission_granularity is also a (currently at least) a content translation specific thing,
It's also an API change.
Two alternatives:
* Transparently store everything that is not a defined property in $this->additional or some other property. No API change.
* Offer separate methods to set arbitrary flags. If combined with enforcing it like here, it would be an API change too.
Comment #21
tim.plunkettThat was my first suggestion to @damiankloip on IRC, I think that is the way forward.
Comment #22
damiankloip commentedI am good with storing additional data in additional. Anything that is not just adding public properties willy nilly :)
Comment #23
tim.plunkettComment #24
damiankloip commentedNice, I like that. And some tests.
Comment #25
tim.plunkettSo the only problem with those tests.... They pass with or without the test.
Is there any way to assert the PHP 5.4 property optimization thing?
Comment #26
damiankloip commentedWell, we could just use ReflectionObject and test for any public properties. That should work fine, like this. Thoughts?
Comment #28
tim.plunkettThanks!
Comment #29
alexpottSo this could potentially break any entity which defines additional already right? So there is some potential disruption.
Comment #30
berdir@alexpott: No, not an entity. It would need to be a custom entity type annotation class, I'm not even sure that is supported with the simple annotation parser that we use now.
Comment #31
alexpott@catch asked in IRC
Can we just remove support for setting undeclared properties?
Comment #32
alexpottFor #31
Comment #33
alexpottAh of course ... hook_entity_type_alter() for example content_translation_entity_type_alter().
Comment #34
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 16f0ab8 and pushed to 8.0.x. Thanks!
I ponder upgrade path and other considerations I think this is safe to do.