We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

[EE4] after_channel_field_update and after_channel_field_save hooks/events not firing when adding or updating a channel field

Developer Preview

Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

I have a few custom fields, and when I edit one and save it, the after_channel_field_update hook is not getting called.

Edit: this seems to also apply to before_channel_entry_save and after_channel_entry_save.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Confirmed, will be fixed in next build!

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

Sweet, thanks!

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

The events are firing, but I think there is a mixup.

When creating a new field after_channel_field_save is called. When editing an existing field after_channel_field_save and after_channel_field_update is called. I don’t believe this was a case in EE3.

I assume it should be:

after_channel_field_save = new after_channel_field_update = edit/update existing

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

That should be correct, actually. The Save hook is meant to fire on all modifications, whether new or existing, then if you need to get granular, use Insert or Update. I’m not aware of this changing from EE3 as I’m pretty sure that’s always how it was meant to work. So, to summarize:

New entity: after_insert and after_save

Existing entity: after_update and after_save

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

You’re right. Maybe I was using them incorrectly in EE3 but never really noticed. Thanks for the clarification.

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

Doesn’t look like after_channel_field_delete is firing though :(

Sorry to inundate you with these.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Yes I can reproduce. Question though: do you know if that hook even worked in EE3? I’m not sure how it would have, looking at things.

       
Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

Yep, because Publisher is using it. If a field is removed I need to also remove it from the publisher table to keep things clean.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

Ahh ok I see what’s happening. It’s due to a performance optimization, which is the same commit that caused no hooks to work in the first place. Will try to find a way around it.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

I think we’ll just do this for now: open system/ee/EllisLab/ExpressionEngine/Service/Model/Model.php and add this to the bottom of the initialize() method:

if ($this->getMetaData('hook_id'))
{
    $this->forwardEventToHooks('delete');
};
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.