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

Hook look

Development and Programming

jwindhorst's avatar
jwindhorst
99 posts
14 years ago
jwindhorst's avatar jwindhorst

We have a requirement for having a publish/edit workflow. This requires that a published entry have the ability to display live even while it is getting edited/approved. I have the base module built, and a pretty good idea of how to tackle the problem. The one place I’m feeling stuck is in looking into how or when a custom field is added to the exp_channel_data table. It appears that each custom field becomes a new column in that table. I would like to be able to hook into the code there so that I can modify a second table in exactly the same manner. I looked through the hooks but I didn’t see one for after a new custom field is created. Hopefully I just missed it though!

       
jwindhorst's avatar
jwindhorst
99 posts
14 years ago
jwindhorst's avatar jwindhorst

Still stuck on this one and running out of things to procrastinate the problem with. Anyone have any thoughts on how I might be able to hook into the “after create custom field” event?

       
jwindhorst's avatar
jwindhorst
99 posts
14 years ago
jwindhorst's avatar jwindhorst

Solved it. If anyone else has a need for it, this is how I got past it.

First, you need to find out where ExpressionEngine creates the new column. This is done in libraries/api/Api_channel_fields.php in the method add_datatype(). If it is merely modifying the column you would use the method edit_datatype(). So once that was found, I created an entry in my config/hooks.php file as such:

$hook['post_controller'] = array(
    'class'     =>  'Api_channel_fields',
    'function'  =>  'add_datatype',
    'filename'  =>  'after_add_custom_field.php',
    'filepath'  =>  'third_party/hooks/',
    'params'    =>  array('field_id'    => $field_id)
);

That will hook onto the end of that function, meaning that the column has already been created. From there it’s fairly academic. Just run a describe on the exp_channel_data table and on your shadow table, in my case exp_workflow_channel_data and then do an array_diff() on the results and add the missing column to the shadow table to sync them back up!

       
Triad's avatar
Triad
44 posts
14 years ago
Triad's avatar Triad

This is almost exactly what i needed to see.. not only that, but the same day? Random.

       
jwindhorst's avatar
jwindhorst
99 posts
14 years ago
jwindhorst's avatar jwindhorst

The thing that gets me is that we specify which codeigniter Class/Method we want to hook into. For you field copy thing you could just attache to the pre-controller hook, and check your column counts every time. It’s a little bit of extra overhead but with as many queryies as EE makes when loading a page anyway, I’m fairly certain it’s not a noticeable slowdown.

       

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.