The extension I am writing requires at least one channel to exist before it will function properly. I want to prevent it from installing if this condition is not met.
I wrote the following code:
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'test',
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
if($this->terminate_extension() ==TRUE)
{
$this->EE->db->insert('extensions', $data);
}
else
{
$this->EE->session->set_flashdata('message_failure','Extension not Installed. At least one layout view needs to be created.');
return FALSE;
}
}It works correctly but the problem is with the extension page. Both the success and a failure message are displayed when only the failure message should be displayed.
Is there a way to turn off the success message, or do I need to figure out another way to handle this case? It would be easy to add this error message in the view file, but that seems kind of kludgy.
Thanks
Tried your idea, figure it would work but it still displays both the success and the error message. I think the notification might be “baked” in JS somewhere. Not really sure. Might need to poke around the code to figure this one out.
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'test',
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => $this->terminate_extension() // retunrs 'y' or 'n'
);
//var_dump($data);
if($this->terminate_extension() == 'y')
{
$this->EE->db->insert('extensions', $data);
}
else
{
$this->EE->session->set_flashdata('message_failure','Extension not Installed. At least one Publish Page Layout needs to be created.');
}
}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.