- Issue created by @berdir
- πΊπΈUnited States nicxvan
Just coming in to say great summary, I think long term if DX is the goal one attribute is better which means we would need to deprecate hook_ENTITY_TYPE_something()
- π¨πSwitzerland berdir Switzerland
One thing that I wasn't sure about, do we have a plan how we will handle documentation of hooks in the future? I can imagine that we'll deprecate the .api.php files and function hook_... stuff and just put those things on the attribute classes? Which also means that we'll want to do attribute classes for all hooks anyway, not just common ones.
Going one step further, I wonder if we want to also start to somehow use those hook classes when invoking hooks? Something like:
\Drupal::moduleHandler()->invokeAll(EntityInsert::hook(), $entity); \Drupal::moduleHandler()->invokeAll(EntityInsert::hook($entity->getEntityTypeId()), $entity);
That would make the place where this hook is invoked explicitly referenced through a class usage. That's often useful and while for example PHPStorm can do that, it requires magic string matching. Especially entity crud hooks are tricky because they are built dynamically in the storage handler.
- π©πͺGermany donquixote
In slack discussions related to π Rethink #[Hook] attribute inheritance Active , we argued that attribute classes are not a good place to document the parameters passed to a hook implementation.
Instead, we decided that we want to link from the attribute class to the old function in *.api.php.
This also means that we can introduce new attributes without changing the hook names.
In this issue we should focus on the attributes.As for attribute names, maybe we should keep a 'Hook' prefix?
This would be to distinguish from other attributes that have nothing to do with hooks.
But I have no super strong opinion, maybe prefix 'Entity' is fine, especially if the implementations all live in 'Hook' namespace. - πΊπΈUnited States dww
FWIW, we did not use
HookFormAlter
orHookPreprocess
as the child attribute names, but justFormAlter
andPreprocess
. So yeah, if they're in theHook
namespace, -1 to also prefixing withHook
.That said, +1 to documenting the hook and parameters in a real function, not in these hook attribute classes.
- πΊπΈUnited States dww
Also, FWIW, e.g. we only have
FormAlter($form_id)
and if you passNULL
you get the generic 'all' approach, and if you pass a value, you get the specific one. So I'd say for consistency we should do the same with these entity hooks and if you pass an$entity_type
value, you get something specific, and if you leave itNULL
, you get all types.Therefore, +1 for a single class that takes an optional arg, not 2 separate attributes.
- πΊπΈUnited States nicxvan
I strongly suspect we will not be doing this after recent relevations.