]> git.mjollnir.org Git - moodle.git/commitdiff
blocks MDL-19902: were seeing empty block columns on the front page when not logged in.
authortjhunt <tjhunt>
Wed, 22 Jul 2009 05:38:28 +0000 (05:38 +0000)
committertjhunt <tjhunt>
Wed, 22 Jul 2009 05:38:28 +0000 (05:38 +0000)
It turns out the only reliable way to find out whether blocks will appear is to get the contents. :-(

lib/blocklib.php
lib/outputlib.php

index 2cb56eb97d7034e8345eb83b798805abde950b12..82520e6b7c8d5caf752261a08f122f54e817e1bb 100644 (file)
@@ -263,21 +263,31 @@ class block_manager {
     /**
      * Determine whether a region contains anything. (Either any real blocks, or
      * the add new block UI.)
+     *
+     * (You may wonder why the $output parameter is required. Unfortunately,
+     * becuase of the way that blocks work, the only reliable way to find out
+     * if a block will be visible is to get the content for output, and to
+     * get the content, you need a renderer. Fortunately, this is not a
+     * performance problem, becuase we cache the output that is generated, and
+     * in almost every case where we call region_has_content, we are about to
+     * output the blocks anyway, so we are not doing wasted effort.)
+     *
      * @param string $region a block region that exists on this page.
+     * @param object $output a moodle_core_renderer. normally the global $OUTPUT. 
      * @return boolean Whether there is anything in this region.
      */
-    public function region_has_content($region) {
+    public function region_has_content($region, $output) {
         if (!$this->is_known_region($region)) {
             return false;
         }
         $this->check_is_loaded();
-        $this->ensure_instances_exist($region);
+        $this->ensure_content_created($region, $output);
         if ($this->page->user_is_editing() && $this->page->user_can_edit_blocks()) {
             // If editing is on, we need all the block regions visible, for the
             // move blocks UI.
             return true;
         }
-        return !empty($this->blockinstances[$region]) || !empty($this->extracontent[$region]);
+        return !empty($this->visibleblockcontent[$region]) || !empty($this->extracontent[$region]);
     }
 
     /**
index e69df92d88993f076653333f1e8da5b2c31e63d9..726fb111bbb18ad88484d9c91f9d3059398188bd 100644 (file)
@@ -1972,7 +1972,7 @@ class moodle_core_renderer extends moodle_renderer_base {
 
         echo '<table id="layout-table"><tr>';
         foreach ($lt as $column) {
-            if ($column == 'left' && $this->page->blocks->region_has_content(BLOCK_POS_LEFT)) {
+            if ($column == 'left' && $this->page->blocks->region_has_content(BLOCK_POS_LEFT, $OUTPUT)) {
                 echo '<td id="left-column" class="block-region" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
                 echo $this->container_start();
                 echo $this->blocks_for_region(BLOCK_POS_LEFT);
@@ -1987,7 +1987,7 @@ class moodle_core_renderer extends moodle_renderer_base {
                 echo $this->container_end();
                 echo '</td>';
 
-            } else if ($column == 'right' && $this->page->blocks->region_has_content(BLOCK_POS_RIGHT)) {
+            } else if ($column == 'right' && $this->page->blocks->region_has_content(BLOCK_POS_RIGHT, $OUTPUT)) {
                 echo '<td id="right-column" class="block-region" style="width: ' . $preferredwidthright . 'px; vertical-align: top;">';
                 echo $this->container_start();
                 echo $this->blocks_for_region(BLOCK_POS_RIGHT);