Problem/Motivation
I want to conditionally invoke the hook based on some criteria. In my case, I want to invoke the hook based on a custom form checkbox I would add to the node form in my own custom module. I can take care of the checkbox and other conditions but there is no way for me to tell build_hooks module to skip that entity for logging.
function build_hooks_entity_insert(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
if (build_hooks_get_logger_service()->isEntityTypeLoggable($entity)) {
build_hooks_get_logger_service()->logEntityCreated($entity);
build_hooks_get_trigger_service()->deployFrontendEntityUpdateEnvironments();
build_hooks_get_trigger_service()->invalidateToolbarCacheTag();
}
}
}
As you can see, there is no way for me to stop the entity being added to the log.
Additional context (optional)
My use case is that I should invoke a notification webhook whenever any content is updated if (and only if) the editor checks a checkbox on the node edit page. My problem is not actually related to "building" any frontend at all, but this is the best module I could find to do this job. If there is a better way, I'll be grateful for pointers.
Proposed resolution
The easiest way I can think of is to fire off a hook from build_hooks_entity_* which will let any module define if that entity should be logged or not. I think a little more sophisticated way to do this would be to dispatch an event where the event object would have specific methods that can say if that particular entity should be logged. I don't think the second approach is particularly hard to do and it would make sense to do that.
Remaining tasks
Decide which approach and write a patch.
User interface changes
None
API changes
If we go with the event-based approach, we would just have a new Event object.
Data model changes
None
Release notes snippet
TBD
Comments