MDL-34899 blocks/html: Allow instances to specify additional CSS classes
authorAaron Barnes <aaronb@catalyst.net.nz>
Wed, 15 Aug 2012 02:04:44 +0000 (14:04 +1200)
committerAaron Barnes <aaronb@catalyst.net.nz>
Mon, 20 Aug 2012 01:27:08 +0000 (13:27 +1200)
blocks/html/block_html.php
blocks/html/edit_form.php
blocks/html/lang/en/block_html.php

index f030401..39040ae 100644 (file)
@@ -131,4 +131,19 @@ class block_html extends block_base {
     public function instance_can_be_docked() {
         return (!empty($this->config->title) && parent::instance_can_be_docked());
     }
+
+    /*
+     * Add custom html attributes to aid with theming and styling
+     *
+     * @return array
+     */
+    function html_attributes() {
+        $attributes = parent::html_attributes();
+
+        if (!empty($this->config->classes)) {
+            $attributes['class'] .= ' '.$this->config->classes;
+        }
+
+        return $attributes;
+    }
 }
index b725190..f544f98 100644 (file)
@@ -41,6 +41,10 @@ class block_html_edit_form extends block_edit_form {
         $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
         $mform->addRule('config_text', null, 'required', null, 'client');
         $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
+
+        $mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
+        $mform->setType('config_classes', PARAM_TEXT);
+        $mform->addHelpButton('config_classes', 'configclasses', 'block_html');
     }
 
     function set_data($defaults) {
index 91f0811..6e82be8 100644 (file)
@@ -23,6 +23,8 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+$string['configclasses'] = 'Additional HTML classes';
+$string['configclasses_help'] = 'The purpose of this configuration is to aid with theming by helping distinguish HTML blocks from each other. Any CSS classes entered here (space delimited) will be appended to the block\'s default classes.';
 $string['configcontent'] = 'Content';
 $string['configtitle'] = 'Block title';
 $string['leaveblanktohide'] = 'leave blank to hide the title';