If from within an extension i want to add some JS to the end of a Channel Publish (or edit) page within the control panel… what would be the best hook to use?
I am looking to modify the behaviour of the pages tab, and i cannot see any hooks that allow me to do this directly. Therefore i am doing this via JS and adding it to the end of the publish page.
Currently i am triggering this via the “publish_form_channel_preferences” hook, and just returning exactly the same settings as are passed in. But not sure if this is the best way - advice or thoughts appreciated.
N
thanks for the post - it actually might be good fit - but my worry is that i am only doing this on the publish page, hence i would hate to continually trigger this hook when it is not needed. But i guess i could get triggered by the hook and then run my own tests - which would still be quite efficient… hmmmm
Here’s a trick I pulled to only have it activate on the publish page:
public function cp_js_end()
{
$this->EE->load->helper('array');
$this->EE->load->library('security');
//get $_GET from the referring page
parse_str(parse_url(@$_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $get);
$output = $this->EE->extensions->last_call;
//check if we're on the publish page
if (element('D', $get) == 'cp' && element('C', $get) == 'content_publish' && element('M', $get) == 'entry_form' && element('channel_id', $get))
{
//do your business here
//$output .= 'alert("blah");';
}
return $output;
}The thing about the cp_js_end hook is that it doesn’t actually occur on the same page load as the cp, it’s loaded as an external script:
< script type="text/javascript" src="index.php?S=0&D=cp&C=javascript&M=load&file=ext_scripts" >So you don’t actually have access to the originating GET variables, because it’s technically a separate request.
As for the overhead, I would personally only worry about it on the front end. It doesn’t bother me to add a few milliseconds to the CP.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.