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!
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!
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.