mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-20204 blocks rendering does not depend on html_component any more
This commit is contained in:
parent
5be262b66f
commit
dd72b308ed
@ -358,7 +358,8 @@ class block_base {
|
||||
public function get_content_for_output($output) {
|
||||
global $CFG;
|
||||
|
||||
$bc = new block_contents();
|
||||
$bc = new block_contents($this->html_attributes());
|
||||
|
||||
$bc->blockinstanceid = $this->instance->id;
|
||||
$bc->blockpositionid = $this->instance->blockpositionid;
|
||||
|
||||
@ -371,17 +372,6 @@ class block_base {
|
||||
$bc->add_class('invisible');
|
||||
}
|
||||
|
||||
$attributes = $this->html_attributes();
|
||||
if (isset($attributes['id'])) {
|
||||
$bc->id = $attributes['id'];
|
||||
unset($attributes['id']);
|
||||
}
|
||||
if (isset($attributes['class'])) {
|
||||
$bc->set_classes($attributes['class']);
|
||||
unset($attributes['class']);
|
||||
}
|
||||
$bc->attributes = $attributes;
|
||||
|
||||
if (!$this->hide_header()) {
|
||||
$bc->title = $this->title;
|
||||
}
|
||||
@ -545,7 +535,7 @@ class block_base {
|
||||
function html_attributes() {
|
||||
$attributes = array(
|
||||
'id' => 'inst' . $this->instance->id,
|
||||
'class' => 'block_' . $this->name()
|
||||
'class' => 'block_' . $this->name(). ' sideblock'
|
||||
);
|
||||
if ($this->instance_can_be_docked() && get_user_preferences('docked_block_instance_'.$this->instance->id, 0)) {
|
||||
$attributes['class'] .= ' dock_on_load';
|
||||
|
@ -286,7 +286,7 @@ class block_manager {
|
||||
* @return string URL for moving block $this->movingblock to this position.
|
||||
*/
|
||||
protected function get_move_target_url($region, $weight) {
|
||||
return $this->page->url->out(false, array('bui_moveid' => $this->movingblock,
|
||||
return new moodle_url($this->page->url, array('bui_moveid' => $this->movingblock,
|
||||
'bui_newregion' => $region, 'bui_newweight' => $weight, 'sesskey' => sesskey()));
|
||||
}
|
||||
|
||||
@ -807,10 +807,7 @@ class block_manager {
|
||||
|
||||
if ($this->movingblock && $lastweight != $instance->instance->weight &&
|
||||
$content->blockinstanceid != $this->movingblock && $lastblock != $this->movingblock) {
|
||||
$bmt = new block_move_target();
|
||||
$bmt->text = $strmoveblockhere;
|
||||
$bmt->url = $this->get_move_target_url($region, ($lastweight + $instance->instance->weight)/2);
|
||||
$results[] = $bmt;
|
||||
$results[] = new block_move_target($strmoveblockhere, $this->get_move_target_url($region, ($lastweight + $instance->instance->weight)/2));
|
||||
}
|
||||
|
||||
if ($content->blockinstanceid == $this->movingblock) {
|
||||
@ -825,10 +822,7 @@ class block_manager {
|
||||
}
|
||||
|
||||
if ($this->movingblock && $lastblock != $this->movingblock) {
|
||||
$bmt = new block_move_target();
|
||||
$bmt->text = $strmoveblockhere;
|
||||
$bmt->url = $this->get_move_target_url($region, $lastweight + 1);
|
||||
$results[] = $bmt;
|
||||
$results[] = new block_move_target($strmoveblockhere, $this->get_move_target_url($region, $lastweight + 1));
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
@ -1757,7 +1757,7 @@ class paging_bar implements renderable {
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class block_contents extends html_component {
|
||||
class block_contents {
|
||||
/** @var int used to set $skipid. */
|
||||
protected static $idcounter = 1;
|
||||
|
||||
@ -1766,7 +1766,7 @@ class block_contents extends html_component {
|
||||
const HIDDEN = 2;
|
||||
|
||||
/**
|
||||
* @param integer $skipid All the blocks (or things that look like blocks)
|
||||
* @var integer $skipid All the blocks (or things that look like blocks)
|
||||
* printed on a page are given a unique number that can be used to construct
|
||||
* id="" attributes. This is set automatically be the {@link prepare()} method.
|
||||
* Do not try to set it manually.
|
||||
@ -1790,7 +1790,7 @@ class block_contents extends html_component {
|
||||
* @param array $attributes an array of attribute => value pairs that are put on the
|
||||
* outer div of this block. {@link $id} and {@link $classes} attributes should be set separately.
|
||||
*/
|
||||
public $attributes = array();
|
||||
public $attributes;
|
||||
|
||||
/**
|
||||
* @param string $title The title of this block. If this came from user input,
|
||||
@ -1831,24 +1831,31 @@ class block_contents extends html_component {
|
||||
*/
|
||||
public $controls = array();
|
||||
|
||||
|
||||
/**
|
||||
* @see html_component::prepare()
|
||||
* @return void
|
||||
* Create new instance of block content
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
public function __construct(array $attributes=null) {
|
||||
$this->skipid = self::$idcounter;
|
||||
self::$idcounter += 1;
|
||||
$this->add_class('sideblock');
|
||||
if (empty($this->blockinstanceid) || !strip_tags($this->title)) {
|
||||
$this->collapsible = self::NOT_HIDEABLE;
|
||||
|
||||
if ($attributes) {
|
||||
// standard block
|
||||
$this->attributes = $attributes;
|
||||
} else {
|
||||
// simple "fake" blocks used in some modules and "Add new block" block
|
||||
$this->attributes = array('class'=>'sideblock');
|
||||
}
|
||||
if ($this->collapsible == self::HIDDEN) {
|
||||
$this->add_class('hidden');
|
||||
}
|
||||
if (!empty($this->controls)) {
|
||||
$this->add_class('block_with_controls');
|
||||
}
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add html class to block
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public function add_class($class) {
|
||||
$this->attributes['class'] .= ' '.$class;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1864,15 +1871,25 @@ class block_contents extends html_component {
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class block_move_target extends html_component {
|
||||
class block_move_target {
|
||||
/**
|
||||
* List of hidden form fields.
|
||||
* @var array
|
||||
* Move url
|
||||
* @var moodle_url
|
||||
*/
|
||||
public $url = array();
|
||||
public $url;
|
||||
/**
|
||||
* List of hidden form fields.
|
||||
* @var array
|
||||
* label
|
||||
* @var string
|
||||
*/
|
||||
public $text = '';
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* Cosntructor
|
||||
* @param string $text
|
||||
* @param moodle_url $url
|
||||
*/
|
||||
public function __construct($text, moodle_url $url) {
|
||||
$this->text = $text;
|
||||
$this->url = $url;
|
||||
}
|
||||
}
|
||||
|
@ -754,22 +754,27 @@ class core_renderer extends renderer_base {
|
||||
* @param string $region the region the block is appearing in.
|
||||
* @return string the HTML to be output.
|
||||
*/
|
||||
function block($bc, $region) {
|
||||
function block(block_contents $bc, $region) {
|
||||
$bc = clone($bc); // Avoid messing up the object passed in.
|
||||
$bc->prepare($this, $this->page, $this->target);
|
||||
if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
|
||||
$bc->collapsible = block_contents::NOT_HIDEABLE;
|
||||
}
|
||||
if ($bc->collapsible == block_contents::HIDDEN) {
|
||||
$bc->add_class('hidden');
|
||||
}
|
||||
if (!empty($bc->controls)) {
|
||||
$bc->add_class('block_with_controls');
|
||||
}
|
||||
|
||||
$skiptitle = strip_tags($bc->title);
|
||||
if (empty($skiptitle)) {
|
||||
$output = '';
|
||||
$skipdest = '';
|
||||
} else {
|
||||
$output = html_writer::tag('a', array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'),
|
||||
get_string('skipa', 'access', $skiptitle));
|
||||
$output = html_writer::tag('a', array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'), get_string('skipa', 'access', $skiptitle));
|
||||
$skipdest = html_writer::tag('span', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'), '');
|
||||
}
|
||||
|
||||
$bc->attributes['id'] = $bc->id;
|
||||
$bc->attributes['class'] = $bc->get_classes_string();
|
||||
$output .= html_writer::start_tag('div', $bc->attributes);
|
||||
|
||||
$controlshtml = $this->block_controls($bc->controls);
|
||||
@ -809,14 +814,14 @@ class core_renderer extends renderer_base {
|
||||
* @param block_contents $bc A block_contents object
|
||||
* @return void
|
||||
*/
|
||||
protected function init_block_hider_js($bc) {
|
||||
if ($bc->collapsible != block_contents::NOT_HIDEABLE) {
|
||||
protected function init_block_hider_js(block_contents $bc) {
|
||||
if (!empty($bc->attributes['id']) and $bc->collapsible != block_contents::NOT_HIDEABLE) {
|
||||
$userpref = 'block' . $bc->blockinstanceid . 'hidden';
|
||||
user_preference_allow_ajax_update($userpref, PARAM_BOOL);
|
||||
$this->page->requires->yui2_lib('dom');
|
||||
$this->page->requires->yui2_lib('event');
|
||||
$plaintitle = strip_tags($bc->title);
|
||||
$this->page->requires->js_function_call('new block_hider', array($bc->id, $userpref,
|
||||
$this->page->requires->js_function_call('new block_hider', array($bc->attributes['id'], $userpref,
|
||||
get_string('hideblocka', 'access', $plaintitle), get_string('showblocka', 'access', $plaintitle),
|
||||
$this->pix_url('t/switch_minus')->out(false), $this->pix_url('t/switch_plus')->out(false)));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user