/** * Return a block_contents object representing the full contents of this block. * * This internally calls ->get_content(), and then adds the editing controls etc. * * You probably should not override this method, but instead override * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()}, * {@link hide_header()}, {@link (get_edit_controls)}, etc. * * @return block_contents a representation of the block, for rendering. * @since Moodle 2.0. */ public function get_content_for_output($output) { global $CFG; $bc = new block_contents($this->html_attributes()); $bc->attributes['data-block'] = $this->name(); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; if ($this->instance->visible) { $bc->content = $this->formatted_contents($output); if (!empty($this->content->footer)) { $bc->footer = $this->content->footer; } } else { $bc->add_class('invisible'); } if (!$this->hide_header()) { $bc->title = $this->title; } if (empty($bc->title)) { $bc->arialabel = new lang_string('pluginname', get_class($this)); $this->arialabel = $bc->arialabel; } if ($this->page->user_is_editing()) { $bc->controls = $this->page->blocks->edit_controls($this); } else { // we must not use is_empty on hidden blocks if ($this->is_empty() && !$bc->controls) { return null; } } if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer) || !$this->instance_can_be_collapsed()) { $bc->collapsible = block_contents::NOT_HIDEABLE; } else { if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) { $bc->collapsible = block_contents::HIDDEN; } else { $bc->collapsible = block_contents::VISIBLE; } } if ($this->instance_can_be_docked() && !$this->hide_header()) { $bc->dockable = true; } $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here. return $bc; }
/** * Return a block_contents oject representing the full contents of this block. * * This internally calls ->get_content(), and then adds the editing controls etc. * * You probably should not override this method, but instead override * {@link html_attributes()}, {@link formatted_contents()} or {@link get_content()}, * {@link hide_header()}, {@link (get_edit_controls)}, etc. * * @return block_contents a represntation of the block, for rendering. * @since Moodle 2.0. */ public function get_content_for_output($output) { global $CFG; $bc = new block_contents($this->html_attributes()); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; if ($this->instance->visible) { $bc->content = $this->formatted_contents($output); if (!empty($this->content->footer)) { $bc->footer = $this->content->footer; } } else { $bc->add_class('invisible'); } if (!$this->hide_header()) { $bc->title = $this->title; } if ($this->page->user_is_editing()) { $bc->controls = $this->page->blocks->edit_controls($this); } if ($this->is_empty() && !$bc->controls) { return null; } if (empty($CFG->allowuserblockhiding) || empty($bc->content) && empty($bc->footer)) { $bc->collapsible = block_contents::NOT_HIDEABLE; } else { if (get_user_preferences('block' . $bc->blockinstanceid . 'hidden', false)) { $bc->collapsible = block_contents::HIDDEN; } else { $bc->collapsible = block_contents::VISIBLE; } } $bc->annotation = ''; // TODO MDL-19398 need to work out what to say here. return $bc; }
/** * Return a {@link block_contents} representing the add a new block UI, if * this user is allowed to see it. * * @return block_contents an appropriate block_contents, or null if the user * cannot add any blocks here. */ function block_add_block_ui($page, $output) { global $CFG, $OUTPUT; if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) { return null; } $bc = new block_contents(); $bc->title = get_string('addblock'); $bc->add_class('block_adminblock'); $missingblocks = $page->blocks->get_addable_blocks(); if (empty($missingblocks)) { $bc->content = get_string('noblockstoaddhere'); return $bc; } $menu = array(); foreach ($missingblocks as $block) { $blockobject = block_instance($block->name); if ($blockobject !== false && $blockobject->user_can_addto($page)) { $menu[$block->name] = $blockobject->get_title(); } } collatorlib::asort($menu); $actionurl = new moodle_url($page->url, array('sesskey' => sesskey())); $select = new single_select($actionurl, 'bui_addblock', $menu, null, array('' => get_string('adddots')), 'add_block'); $select->set_label(get_string('addblock'), array('class' => 'accesshide')); $bc->content = $OUTPUT->render($select); return $bc; }
/** * Return a {@link block_contents} representing the add a new block UI, if * this user is allowed to see it. * * @return block_contents an appropriate block_contents, or null if the user * cannot add any blocks here. */ function block_add_block_ui($page, $output) { global $CFG, $OUTPUT; if (!$page->user_is_editing() || !$page->user_can_edit_blocks()) { return null; } $bc = new block_contents(); $bc->title = get_string('addblock'); $bc->add_class('block_adminblock'); $missingblocks = $page->blocks->get_addable_blocks(); if (empty($missingblocks)) { $bc->content = get_string('noblockstoaddhere'); return $bc; } $menu = array(); foreach ($missingblocks as $block) { $blockobject = block_instance($block->name); if ($blockobject !== false && $blockobject->user_can_addto($page)) { $menu[$block->name] = $blockobject->get_title(); } } asort($menu, SORT_LOCALE_STRING); $actionurl = $page->url->out_action(); $select = html_select::make_popup_form($actionurl, 'bui_addblock', $menu, 'add_block'); $select->nothinglabel = get_string('adddots'); $bc->content = $OUTPUT->select($select); return $bc; }