Skip to content

Commit

Permalink
MDL-41516 Themes: Ensure that blocks are set up early
Browse files Browse the repository at this point in the history
Blocks can require JavaScript which must be set up early in the page
lifecycle.
In order to do so, we should ensure that content is created in the standard
head setup before any other output is created so that any subsequent use of
block instances are no longer the first such use when they may already be
too late in the lifecycle.
  • Loading branch information
andrewnicols committed Sep 1, 2013
1 parent ee78814 commit 59849f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ protected function ensure_instances_exist($region) {
*
* @param string $region The name of the region to check
*/
protected function ensure_content_created($region, $output) {
public function ensure_content_created($region, $output) {
$this->ensure_instances_exist($region);
if (!array_key_exists($region, $this->visibleblockcontent)) {
$contents = array();
Expand Down
10 changes: 10 additions & 0 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ public function htmlattributes() {
*/
public function standard_head_html() {
global $CFG, $SESSION;

// Before we output any content, we need to ensure that certain
// page components are set up.

// Blocks must be set up early as they may require javascript which
// has to be included in the page header before output is created.
foreach ($this->page->blocks->get_regions() as $region) {
$this->page->blocks->ensure_content_created($region, $this);
}

$output = '';
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n";
$output .= '<meta name="keywords" content="moodle, ' . $this->page->title . '" />' . "\n";
Expand Down

0 comments on commit 59849f7

Please sign in to comment.