Permalink
Browse files

MDL-41516 Themes: Ensure that blocks are set up early

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...
1 parent 0bd9f00 commit 7402dcd5fdbb9cfda0b42b677aff7f578276b192 @andrewnicols andrewnicols committed Sep 1, 2013
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/blocklib.php
  2. +10 −0 lib/outputrenderers.php
View
@@ -993,7 +993,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();
View
@@ -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";

0 comments on commit 7402dcd

Please sign in to comment.