Skip to content

Commit

Permalink
moodle_page: MDL-12212 Eliminate legacy blocks_ methods
Browse files Browse the repository at this point in the history
moving blocks will now be broken until the new bockslib is done
  • Loading branch information
tjhunt committed May 6, 2009
1 parent 4912752 commit 4873f5f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 169 deletions.
17 changes: 0 additions & 17 deletions admin/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,6 @@ function url_get_parameters() { // only handles parameters relevant to the admi
return array_merge($this->extraurlparams, array('section' => $this->section));
}

function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

function blocks_default_position() {
return BLOCK_POS_LEFT;
}

function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}

function print_header($section = '', $focus='') {
global $USER, $CFG, $SITE;

Expand Down
42 changes: 0 additions & 42 deletions blog/blogpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,48 +110,6 @@ function url_get_parameters() {
return $array;
}


// Having defined all identifiers we need, here we declare which block positions we are
// going to support.
function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

// When a new block is created in this page, which position should it go to?
function blocks_default_position() {
return BLOCK_POS_RIGHT;
}

// When we are creating a new page, use the data at your disposal to provide a textual representation of the
// blocks that are going to get added to this new page. Delimit block names with commas (,) and use double
// colons (:) to delimit between block positions in the page. See blocks_get_positions() for additional info.
function blocks_get_default() {
global $CFG;

$this->init_full();

// It's a normal blog page
if (!empty($CFG->{'defaultblocks_'. $this->pagetype})) {
$blocknames = $CFG->{'defaultblocks_'. $this->pagetype};
} else {
/// Failsafe - in case nothing was defined.
$blocknames = 'admin,calendar_month,online_users,blog_menu';
}

return $blocknames;
}

// And finally, a little block move logic. Given a block's previous position and where
// we want to move it to, return its new position. Pretty self-documenting.
function blocks_move_position(&$instance, $move) {
if ($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}

/////////// Blog page specific functions
function get_extra_header_string() {
global $SESSION, $CFG, $USER;
Expand Down
92 changes: 33 additions & 59 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,38 @@ public function get_legacyclass() {
debugging('Call to deprecated method moodle_page::get_legacyclass.');
return $this->_legacyclass;
}

/**
* @deprecated since Moodle 2.0
* @return string the places on this page where blocks can go.
*/
function blocks_get_positions() {
debugging('Call to deprecated method moodle_page::blocks_get_positions. Use $PAGE->blocks->get_positions() instead.');
return $PAGE->blocks->get_positions();
}

/**
* @deprecated since Moodle 2.0
* @return string the default place for blocks on this page.
*/
function blocks_default_position() {
debugging('Call to deprecated method moodle_page::blocks_default_position. Use $PAGE->blocks->get_default_position() instead.');
return $PAGE->blocks->get_default_position();
}

/**
* @deprecated since Moodle 2.0 - no longer used.
*/
function blocks_get_default() {
debugging('Call to deprecated method moodle_page::blocks_get_default. This method has no function any more.');
}

/**
* @deprecated since Moodle 2.0 - no longer used.
*/
function blocks_move_position(&$instance, $move) {
debugging('Call to deprecated method moodle_page::blocks_move_position. This method has no function any more.');
}
}

/**
Expand Down Expand Up @@ -675,32 +707,6 @@ function print_header($title, $morenavlinks=NULL) {
return;
}

// BLOCKS RELATED SECTION

// By default, pages don't have any blocks. Override this in your derived class if you need blocks.
function blocks_get_positions() {
return array();
}

// Thus there is no default block position. If you override the above you should override this one too.
// Because this makes sense only if blocks_get_positions() is overridden and because these two should
// be overridden as a group or not at all, this one issues a warning. The sneaky part is that this warning
// will only be seen if you override blocks_get_positions() but NOT blocks_default_position().
function blocks_default_position() {
trigger_error('Page class does not implement method <strong>blocks_default_position()</strong>', E_USER_WARNING);
return NULL;
}

// If you don't override this, newly constructed pages of this kind won't have any blocks.
function blocks_get_default() {
return '';
}

// If you don't override this, your blocks will not be able to change positions
function blocks_move_position(&$instance, $move) {
return $instance->position;
}

// SELF-REPORTING SECTION

// Derived classes HAVE to define their "home url"
Expand Down Expand Up @@ -926,26 +932,10 @@ function url_get_parameters() {
}
}

// BLOCKS RELATED SECTION

// Which are the positions in this page which support blocks? Return an array containing their identifiers.
// BE CAREFUL, ORDER DOES MATTER! In textual representations, lists of blocks in a page use the ':' character
// to delimit different positions in the page. The part before the first ':' in such a representation will map
// directly to the first item of the array you return here, the second to the next one and so on. This way,
// you can add more positions in the future without interfering with legacy textual representations.
function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

// When a new block is created in this page, which position should it go to?
function blocks_default_position() {
return BLOCK_POS_RIGHT;
}

// When we are creating a new page, use the data at your disposal to provide a textual representation of the
// blocks that are going to get added to this new page. Delimit block names with commas (,) and use double
// colons (:) to delimit between block positions in the page. See blocks_get_positions() for additional info.
function blocks_get_default() {
function _legacy_blocks_get_default() {
global $CFG;

$this->init_full();
Expand Down Expand Up @@ -986,22 +976,6 @@ function blocks_get_default() {

return $blocknames;
}

// Given an instance of a block in this page and the direction in which we want to move it, where is
// it going to go? Return the identifier of the instance's new position. This allows us to tell blocklib
// how we want the blocks to move around in this page in an arbitrarily complex way. If the move as given
// does not make sense, make sure to return the instance's original position.
//
// Since this is going to get called a LOT, pass the instance by reference purely for speed. Do **NOT**
// modify its data in any way, this will actually confuse blocklib!!!
function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}
}

/**
Expand Down
17 changes: 0 additions & 17 deletions mod/lesson/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,6 @@ function print_header($title = '', $morenavlinks = array()) {
lesson_print_messages();
}

function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

function blocks_default_position() {
return BLOCK_POS_RIGHT;
}

function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}

/**
* Needed to add the ID of the current lesson page
*
Expand Down
17 changes: 0 additions & 17 deletions my/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,6 @@ function url_get_parameters() {
return array();
}
}

function blocks_default_position() {
return BLOCK_POS_LEFT;
}

function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}
}


Expand Down
17 changes: 0 additions & 17 deletions tag/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ function url_get_parameters() {
$param['id'] = $this->id;
return $param;
}

function blocks_default_position() {
return BLOCK_POS_LEFT;
}

function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}

function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}

//----------- printing funtions -----------

Expand Down

0 comments on commit 4873f5f

Please sign in to comment.