mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
blocks editing ui: MDL-19398 move generating the block edit icons to blocklib.php
Since that is where the resulting actions are processed.
This commit is contained in:
parent
727ae4362e
commit
1936f20b8b
3 changed files with 58 additions and 59 deletions
|
@ -361,7 +361,7 @@ class block_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->page->user_is_editing()) {
|
if ($this->page->user_is_editing()) {
|
||||||
$bc->controls = $this->get_edit_controls($output);
|
$bc->controls = block_edit_controls($this, $this->page);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->is_empty() && !$bc->controls) {
|
if ($this->is_empty() && !$bc->controls) {
|
||||||
|
@ -402,62 +402,6 @@ class block_base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the appropriate list of editing icons for this block. This is used
|
|
||||||
* to set {@link block_contents::$controls} in {@link get_contents_for_output()}.
|
|
||||||
*
|
|
||||||
* @param $output The core_renderer to use when generating the output. (Need to get icon paths.)
|
|
||||||
* @return an array in the format for {@link block_contents::$controls}
|
|
||||||
* @since Moodle 2.0.
|
|
||||||
*/
|
|
||||||
protected function get_edit_controls($output) {
|
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
$returnurlparam = '&returnurl=' . urlencode($this->page->url->out_returnurl());
|
|
||||||
$actionurl = $this->page->url->out_action();
|
|
||||||
|
|
||||||
$controls = array();
|
|
||||||
|
|
||||||
// Assign roles icon.
|
|
||||||
if (has_capability('moodle/role:assign', $this->context)) {
|
|
||||||
$controls[] = array('url' => $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$this->context->id,
|
|
||||||
'icon' => $output->old_icon_url('i/roles'), 'caption' => get_string('assignroles', 'role'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->user_can_edit() && $this->page->user_can_edit_blocks()) {
|
|
||||||
// Show/hide icon.
|
|
||||||
if ($this->instance->visible) {
|
|
||||||
$controls[] = array('url' => $actionurl . '&action=hide',
|
|
||||||
'icon' => $output->old_icon_url('t/hide'), 'caption' => get_string('hide'));
|
|
||||||
} else {
|
|
||||||
$controls[] = array('url' => $actionurl . '&action=show',
|
|
||||||
'icon' => $output->old_icon_url('t/show'), 'caption' => get_string('show'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edit config icon.
|
|
||||||
if ($this->instance_allow_multiple() || $this->instance_allow_config()) {
|
|
||||||
$editurl = $CFG->wwwroot . '/blocks/edit.php?block=' . $this->instance->id;
|
|
||||||
if (!empty($this->instance->blockpositionid)) {
|
|
||||||
$editurl .= '&positionid=' . $this->instance->blockpositionid;
|
|
||||||
}
|
|
||||||
$controls[] = array('url' => $editurl . $returnurlparam,
|
|
||||||
'icon' => $output->old_icon_url('t/edit'), 'caption' => get_string('configuration'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete icon.
|
|
||||||
if ($this->user_can_addto($this->page)) {
|
|
||||||
$controls[] = array('url' => $actionurl . '&bui_deleteid=' . $this->instance->id,
|
|
||||||
'icon' => $output->old_icon_url('t/delete'), 'caption' => get_string('delete'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move icon.
|
|
||||||
$controls[] = array('url' => $this->page->url->out(false, array('moveblockid' => $this->instance->id)),
|
|
||||||
'icon' => $output->old_icon_url('t/move'), 'caption' => get_string('move'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $controls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if this block has been implemented correctly.
|
* Tests if this block has been implemented correctly.
|
||||||
* Also, $errors isn't used right now
|
* Also, $errors isn't used right now
|
||||||
|
|
|
@ -838,6 +838,60 @@ function block_add_block_ui($page, $output) {
|
||||||
return $bc;
|
return $bc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the appropriate list of editing icons for a block. This is used
|
||||||
|
* to set {@link block_contents::$controls} in {@link block_base::get_contents_for_output()}.
|
||||||
|
*
|
||||||
|
* @param $output The core_renderer to use when generating the output. (Need to get icon paths.)
|
||||||
|
* @return an array in the format for {@link block_contents::$controls}
|
||||||
|
* @since Moodle 2.0.
|
||||||
|
*/
|
||||||
|
function block_edit_controls($block, $page) {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$controls = array();
|
||||||
|
$actionurl = $page->url->out_action();
|
||||||
|
|
||||||
|
// Assign roles icon.
|
||||||
|
if (has_capability('moodle/role:assign', $block->context)) {
|
||||||
|
$controls[] = array('url' => $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$block->context->id,
|
||||||
|
'icon' => 'i/roles', 'caption' => get_string('assignroles', 'role'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($block->user_can_edit() && $page->user_can_edit_blocks()) {
|
||||||
|
// Show/hide icon.
|
||||||
|
if ($block->instance->visible) {
|
||||||
|
$controls[] = array('url' => $actionurl . '&action=hide',
|
||||||
|
'icon' => 't/hide', 'caption' => get_string('hide'));
|
||||||
|
} else {
|
||||||
|
$controls[] = array('url' => $actionurl . '&action=show',
|
||||||
|
'icon' => 't/show', 'caption' => get_string('show'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit config icon.
|
||||||
|
if ($block->instance_allow_multiple() || $block->instance_allow_config()) {
|
||||||
|
$editurl = $CFG->wwwroot . '/blocks/edit.php?block=' . $block->instance->id;
|
||||||
|
if (!empty($block->instance->blockpositionid)) {
|
||||||
|
$editurl .= '&positionid=' . $block->instance->blockpositionid;
|
||||||
|
}
|
||||||
|
$controls[] = array('url' => $editurl . '&returnurl=' . urlencode($page->url->out_returnurl()),
|
||||||
|
'icon' => 't/edit', 'caption' => get_string('configuration'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete icon.
|
||||||
|
if ($block->user_can_addto($page)) {
|
||||||
|
$controls[] = array('url' => $actionurl . '&bui_deleteid=' . $block->instance->id,
|
||||||
|
'icon' => 't/delete', 'caption' => get_string('delete'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move icon.
|
||||||
|
$controls[] = array('url' => $page->url->out(false, array('moveblockid' => $block->instance->id)),
|
||||||
|
'icon' => 't/move', 'caption' => get_string('move'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $controls;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process any block actions that were specified in the URL.
|
* Process any block actions that were specified in the URL.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2007,7 +2007,7 @@ class moodle_core_renderer extends moodle_renderer_base {
|
||||||
foreach ($controls as $control) {
|
foreach ($controls as $control) {
|
||||||
$controlshtml[] = $this->output_tag('a', array('class' => 'icon',
|
$controlshtml[] = $this->output_tag('a', array('class' => 'icon',
|
||||||
'title' => $control['caption'], 'href' => $control['url']),
|
'title' => $control['caption'], 'href' => $control['url']),
|
||||||
$this->output_empty_tag('img', array('src' => $control['icon'],
|
$this->output_empty_tag('img', array('src' => $this->old_icon_url($control['icon']),
|
||||||
'alt' => $control['caption'])));
|
'alt' => $control['caption'])));
|
||||||
}
|
}
|
||||||
return $this->output_tag('div', array('class' => 'commands'), implode('', $controlshtml));
|
return $this->output_tag('div', array('class' => 'commands'), implode('', $controlshtml));
|
||||||
|
@ -2748,7 +2748,8 @@ class block_contents extends moodle_html_component {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A (possibly empty) array of editing controls. Each element of this array
|
* A (possibly empty) array of editing controls. Each element of this array
|
||||||
* should be an array('url' => $url, 'icon' => $icon, 'caption' => $caption)
|
* should be an array('url' => $url, 'icon' => $icon, 'caption' => $caption).
|
||||||
|
* $icon is the icon name. Fed to $OUTPUT->old_icon_url.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $controls = array();
|
public $controls = array();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue