Skip to content

Commit

Permalink
Dev Added support for the beforeActivate callback, included an exampl…
Browse files Browse the repository at this point in the history
…e plugin.
  • Loading branch information
SamMousa committed Mar 27, 2013
1 parent 3db4daa commit f49e26b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions application/controllers/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ public function actionActivate($id)
if ($result->get('success', true)) {
$status = 0;
} else {
echo "Failed to deactivate";
Yii::app()->end();
App()->user->setFlash('pluginActivation', gT('Failed to deactivate the plugin.'));
$this->redirect(array('plugins/'));
}

} else {
// Load the plugin:
App()->getPluginManager()->loadPlugin($plugin->name, $id);
$result = App()->getPluginManager()->dispatchEvent(new PluginEvent('beforeActivate', $this), $plugin->name);
if ($result->get('success', true)) {
$status = 1;
} else {
echo "Failed to activate";
Yii::app()->end();
App()->user->setFlash('pluginActivation', $result->get('message', gT('Failed to activate plugin.')));
$this->redirect(array('plugins/'));
}
}
$plugin->active = $status;
Expand Down
21 changes: 21 additions & 0 deletions plugins/UnActivatable/UnActivatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Example plugin that can not be activated.
*/
class UnActivatable extends PluginBase
{

public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
$this->subscribe('beforeActivate');
}

public function beforeActivate(PluginEvent $event)
{
$event->set('success', false);

// Optionally set a custom error message.
$event->set('message', 'Custom error message from plugin.');
}
}
?>

0 comments on commit f49e26b

Please sign in to comment.