]> git.mjollnir.org Git - moodle.git/commitdiff
blocks editing ui: MDL-19398 move generating the block edit icons to blocklib.php
authortjhunt <tjhunt>
Tue, 14 Jul 2009 10:57:06 +0000 (10:57 +0000)
committertjhunt <tjhunt>
Tue, 14 Jul 2009 10:57:06 +0000 (10:57 +0000)
Since that is where the resulting actions are processed.

blocks/moodleblock.class.php
lib/blocklib.php
lib/outputlib.php

index 722f415e778dca722cf4f01fa76f1d91cb186ee3..2202d8f711d61367d98535546880bbe3874ae5e9 100644 (file)
@@ -361,7 +361,7 @@ class block_base {
         }
 
         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) {
@@ -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 = '&amp;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 . '&amp;action=hide',
-                        'icon' => $output->old_icon_url('t/hide'), 'caption' => get_string('hide'));
-            } else {
-                $controls[] = array('url' => $actionurl . '&amp;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 .= '&amp;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 . '&amp;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.
      * Also, $errors isn't used right now
index 5eb1f7f50cb402c29a626d27505621d8686ec596..17686d36df61cd6613c2bfb4f3f06a6b36c33243 100644 (file)
@@ -838,6 +838,60 @@ function block_add_block_ui($page, $output) {
     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 . '&amp;action=hide',
+                    'icon' => 't/hide', 'caption' => get_string('hide'));
+        } else {
+            $controls[] = array('url' => $actionurl . '&amp;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 .= '&amp;positionid=' . $block->instance->blockpositionid;
+            }
+            $controls[] = array('url' => $editurl . '&amp;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 . '&amp;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.
  * 
index 3809989d8cf91e2a2f209ccb1a41250f56afc50e..5e6f16abcbc1a0c179e41d2166a87b12643a3960 100644 (file)
@@ -2007,7 +2007,7 @@ class moodle_core_renderer extends moodle_renderer_base {
         foreach ($controls as $control) {
             $controlshtml[] = $this->output_tag('a', array('class' => 'icon',
                     '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'])));
         }
         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
-     * 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
      */
     public $controls = array();