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;
$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;
}
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';
* @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()));
}
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) {
}
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;
* @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;
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.
* @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,
*/
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 ($this->collapsible == self::HIDDEN) {
- $this->add_class('hidden');
- }
- if (!empty($this->controls)) {
- $this->add_class('block_with_controls');
+
+ 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');
}
- parent::prepare($output, $page, $target);
+ }
+
+ /**
+ * Add html class to block
+ * @param string $class
+ * @return void
+ */
+ public function add_class($class) {
+ $this->attributes['class'] .= ' '.$class;
}
}
* @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;
+ }
}
* @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);
* @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)));
}