Skip to content

Commit

Permalink
Extend block_manager to handle sidebar blocks. get_available has beco…
Browse files Browse the repository at this point in the history
…me get_available_admin_blocks, get_list becomes get_admin_list. Create new functions get_available_site_blocks which will look for gallery_block get_available_site_blocks
  • Loading branch information
Tim Almdal committed Sep 29, 2009
1 parent 39cd84d commit d77045f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/comment/helpers/comment_block.php
Expand Up @@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class comment_block_Core {
static function get_list() {
static function get_admin_list() {
return array("recent_comments" => t("Recent Comments"));
}

Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/controllers/admin_dashboard.php
Expand Up @@ -34,7 +34,7 @@ public function add_block() {
$form = gallery_block::get_add_block_form();
if ($form->validate()) {
list ($module_name, $id) = explode(":", $form->add_block->id->value);
$available = block_manager::get_available();
$available = block_manager::get_available_admin_blocks();

if ($form->add_block->center->value) {
block_manager::add("dashboard_center", $module_name, $id);
Expand Down Expand Up @@ -66,7 +66,7 @@ public function remove_block($id) {
}

if (!empty($deleted)) {
$available = block_manager::get_available();
$available = block_manager::get_available_admin_blocks();
$title = $available[join(":", $deleted)];
message::success(t("Removed <b>%title</b> block", array("title" => $title)));
}
Expand Down
14 changes: 11 additions & 3 deletions modules/gallery/helpers/block_manager.php
Expand Up @@ -38,13 +38,21 @@ static function remove($location, $block_id) {
self::set_active($location, $blocks);
}

static function get_available() {
static function get_available_admin_blocks() {
return self::_get_blocks("get_admin_list");
}

static function get_available_site_blocks() {
return self::_get_blocks("get_site_list");
}

private static function _get_blocks($function) {
$blocks = array();

foreach (module::active() as $module) {
$class_name = "{$module->name}_block";
if (method_exists($class_name, "get_list")) {
foreach (call_user_func(array($class_name, "get_list")) as $id => $title) {
if (method_exists($class_name, $function)) {
foreach (call_user_func(array($class_name, $function)) as $id => $title) {
$blocks["{$module->name}:$id"] = $title;
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/gallery/helpers/gallery_block.php
Expand Up @@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_block_Core {
static function get_list() {
static function get_admin_list() {
return array(
"welcome" => t("Welcome to Gallery 3!"),
"photo_stream" => t("Photo Stream"),
Expand Down Expand Up @@ -94,7 +94,8 @@ static function get_add_block_form() {
$form = new Forge("admin/dashboard/add_block", "", "post",
array("id" => "gAddDashboardBlockForm"));
$group = $form->group("add_block")->label(t("Add Block"));
$group->dropdown("id")->label(t("Available Blocks"))->options(block_manager::get_available());
$group->dropdown("id")->label(t("Available Blocks"))
->options(block_manager::get_available_admin_blocks());
$group->submit("center")->value(t("Add to center"));
$group->submit("sidebar")->value(t("Add to sidebar"));
return $form;
Expand Down

0 comments on commit d77045f

Please sign in to comment.