From within a plug-in, is there anyway I can get a valid instantiated extension class handle? Long story short, I want to add a plugin to my CoolLocation geocode extension that will stuff everything into a SAEF form. All the settings etc and all in the extension and settings, So I just would like to call a function of my class to return the proper JS code.
alternatively, how do I instantiate an extension and have it get is current settings? -kevin
I’m not sure if this is the ‘correct’ way to do it - I’d love to hear other people’s thoughts. But I did just this recently with a plug-in that needed the settings of an extension.
What I did was make a function within the extension that simply returned the settings like so:
function reason () {
if($this->settings) {
return $this->settings['closing'];
} else {
return false;
}
}
In the activate_extension function of that extension I gave it a hook that I made up for the purpose - like so:
function activate_extension () {
global $DB;
$DB->query($DB->insert_string('exp_extensions', array('extension_id' => '',
'class' => get_class($this),
'method' => 'reason',
'hook' => 'bfpl_closing_hook',
'settings' => '',
'priority' => 5,
'version' => $this->version,
'enabled' => 'y')));
}
Then within the plug-in, I called that extension hook:
function closing()
{
global $TMPL, $EXT;
$reason = $EXT->call_extension('bfpl_closing_hook');
if($reason) {
$this->return_data = '' . $reason . '';
} else {
$this->return_data = $TMPL->tagdata;
}
}
Like I said I have no clue if this is the correct way of doing things, but it works… I’d love to hear if this is the right way of doing things or if there is a better way.
I just had completed the following before I received your post. Again, I have no idea if it is “proper” but it works in 1.6.1 for me. All this code can be anywhere within the plug-in.
global $TMPL, $FNS, $EXT, $REGX;
$class = 'CoolLocation_extension';
$ext_hook = 'publish_form_new_tabs';
$path = PATH_EXT.'ext.'.$FNS->filename_security(strtolower($class)).EXT;
$settings_list = $EXT->extensions[$ext_hook];
foreach ($settings_list as $setting_group) {
if (isset($setting_group[$class])) {
$seralized_settings = $setting_group[$class][1];
break;
}
}
$settings = $REGX->array_stripslashes(unserialize($seralized_settings));
if (!class_exists($class)) {
require $path;
}
$myext = new $class($settings);
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.