summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-09-30 17:30:01 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-09-30 17:30:01 -0700
commit81eaf1e46cb1646bf6b5d5c2f86ea3b3c7a0bd06 (patch)
tree55c08dfa432a20eae6bb99a8723e65239d4a4d34
parente197e4017daa0833cec84d8392e4d05cdf81503d (diff)
Add functionality to activate sidebar blocks when the module is activated and deactivate the sidebar blocks when the module is deactivated.
-rw-r--r--modules/gallery/helpers/block_manager.php23
-rw-r--r--modules/gallery/helpers/gallery_installer.php2
-rw-r--r--modules/gallery/helpers/module.php6
3 files changed, 30 insertions, 1 deletions
diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php
index 233e4f2e..906a251d 100644
--- a/modules/gallery/helpers/block_manager.php
+++ b/modules/gallery/helpers/block_manager.php
@@ -32,12 +32,35 @@ class block_manager_Core {
self::set_active($location, $blocks);
}
+ static function activate_sidebar_blocks($module_name) {
+ $block_class = "{$module_name}_block";
+ if (method_exists($block_class, "get_site_list")) {
+ $blocks = call_user_func(array($block_class, "get_site_list"));
+ Kohana::log("error", Kohana::debug($blocks));
+ foreach (array_keys($blocks) as $id) {
+ list ($unused, $block_id) = explode(":", $id);
+ self::add("site.sidebar", $module_name, $block_id);
+ }
+ }
+ }
+
static function remove($location, $block_id) {
$blocks = self::get_active($location);
unset($blocks[$block_id]);
self::set_active($location, $blocks);
}
+ static function deactivate_sidebar_blocks($module_name) {
+ $block_class = "{$module_name}_block";
+ if (method_exists($block_class, "get_site_list")) {
+ $blocks = call_user_func(array($block_class, "get_site_list"));
+ foreach (array_keys($blocks) as $id) {
+ list ($unused, $block_id) = explode(":", $id);
+ self::remove("site.sidebar", $module_name, $block_id);
+ }
+ }
+ }
+
static function get_available_admin_blocks() {
return self::_get_blocks("get_admin_list");
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 743808ea..b1ea1f19 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -386,7 +386,7 @@ class gallery_installer {
$sidebar_blocks = block_manager::get_active("site.sidebar");
if (empty($sidebar_blocks)) {
$available_blocks = block_manager::get_available_site_blocks();
- foreach (array_key(block_manager::get_available_site_blocks()) as $id) {
+ foreach (array_keys(block_manager::get_available_site_blocks()) as $id) {
$sidebar_blocks[] = explode(":", $id);
}
block_manager::set_active("site.sidebar", $sidebar_blocks);
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index a27fdbc5..fe37f4f9 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -195,6 +195,9 @@ class module_Core {
module::load_modules();
graphics::activate_rules($module_name);
+
+ block_manager::activate_sidebar_blocks($module_name);
+
log::success(
"module", t("Activated module %module_name", array("module_name" => $module_name)));
}
@@ -219,6 +222,9 @@ class module_Core {
module::load_modules();
graphics::deactivate_rules($module_name);
+
+ block_manager::deactivate_sidebar_blocks($module_name);
+
log::success(
"module", t("Deactivated module %module_name", array("module_name" => $module_name)));
}