Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
4 Feb 2014 at 22:02 UTC
Updated:
29 Jul 2014 at 23:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tim.plunkettWe need to use module_implements_alter the same as content_translation.
I attached a whitespace-ignoring patch as well, since a big chunk is just indented. config_translation_entity_info was running on all entity types, heh.
Comment #3
tim.plunkettOh, FieldInstance. It defines it's edit-form dynamically, so we have to do the same thing for this.
However, instead of throwing another moduleExists in there, we can just check the link templates, in case another module eventually wants to supplant config_translation...
Comment #4
Crell commentedI think I missed something... WTF does that method do, and why isn't it instanceof??
The purpose of this function completely escapes me. Pretty much all uses of module_implements_alter() are a fugly hack indicating bad underlying architecture. Surely we can do better than that in core.
Comment #5
tim.plunkett4.1) So we used to have 2 different flavors of this in core:
is_subclass_of($entity_info['class'], 'Foo')
in_array(class_implements($entity_info['class']) 'Foo')
And there might have been one more.
So we now have
4.2)
Yeah, okay, suggestions welcome. content_translation does the same thing for the same reason.
Comment #6
Crell commentedPoint 1: Um. Um. Those two examples you list are for when we have a class name, and want to know if that class is a sublcass of/implements interface X. The method in question is operating on an object. For an object if ($foo instanceof Class) will work for both parent classes and interfaces. Different use case. $foo->isSubclassOf(), as written here, should be identical to instanceof, except instanceof pays attention to use statements.
One of us is missing something patently obvious. It's after midnight here though, so it's a tossup as to which of us it is. :-)
Comment #7
tim.plunkettLet's say you want to know if a node is a ContentEntity or a ConfigEntity.
You don't have an instance of the Node class, so you cannot do
$node instanceof ContentEntityInterface.You have the entity type info. The thing that if you call $entity_type->getClass() will return \Drupal\node\Entity\Node.
Comment #8
berdirAbout the hook stuff, would it help to use the alter hook?
We are adding new controller classes, but we're also adding them to existing entity types, we don't define our own, so we alter those.
Comment #9
tim.plunkettGood point, content_translation uses hook_entity_info_alter, and its my fault we don't use that in config_translation.
Switching that around and removing the hook_module_implements_alter works fine.
Comment #10
berdirI think this looks good. The dynamic stuff for the FieldInstance is a bit special, but necessary I think.
This will overlap with #1981858: Rename hook_entity_info/alter() to hook_entity_type_build/alter(), but shouldn't be a complicated re-roll for either issue, so I don't care which one gets in first.
Comment #11
Crell commentedUh. In what situatoin are nodes ConfigEntities? Isn't the whole point of ConfigEntities that we can stop bastardizing nodes like that? And if you don't have an instance of the object, what are you calling -> on (as opposed to ::)?
That is still an unexplained design flaw for me at this point. Reimplementing language functionality in user space is a major code smell. If we're using that as a proxy for some other higher-level operation/inspection, then we should just outright do that and rename the method (even if the implementation happens to be similar, which I'm still not convinced of).
Comment #12
tim.plunkett@Crell, you either did not read what I wrote, or did not actually read the code, or both. I opened #2194783: Rename EntityTypeInterface::isSubclassOf() to ::entityClassImplements() to just put that to bed.
Comment #13
alexpottCommitted f451e3d and pushed to 8.x. Thanks!
Fixed during commit.