From 055cc8353d6dc0b342b4b36af9dbaf8e73e206ec Mon Sep 17 00:00:00 2001 From: Aaron Barnes Date: Fri, 24 Aug 2012 12:05:52 +1200 Subject: [PATCH] MDL-35042 blocks: Allow HTML block advanced setting to be toggled --- blocks/html/block_html.php | 12 ++++++++++-- blocks/html/edit_form.php | 10 +++++++--- blocks/html/lang/en/block_html.php | 4 +++- blocks/html/settings.php | 10 ++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 blocks/html/settings.php diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index 39040ae47dd..b616925d70d 100644 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -29,6 +29,10 @@ class block_html extends block_base { $this->title = get_string('pluginname', 'block_html'); } + function has_config() { + return true; + } + function applicable_formats() { return array('all' => true); } @@ -138,10 +142,14 @@ class block_html extends block_base { * @return array */ function html_attributes() { + global $CFG; + $attributes = parent::html_attributes(); - if (!empty($this->config->classes)) { - $attributes['class'] .= ' '.$this->config->classes; + if (!empty($CFG->block_html_allowcssclasses)) { + if (!empty($this->config->classes)) { + $attributes['class'] .= ' '.$this->config->classes; + } } return $attributes; diff --git a/blocks/html/edit_form.php b/blocks/html/edit_form.php index f544f98cee0..edb57055fd0 100644 --- a/blocks/html/edit_form.php +++ b/blocks/html/edit_form.php @@ -31,6 +31,8 @@ */ class block_html_edit_form extends block_edit_form { protected function specific_definition($mform) { + global $CFG; + // Fields for editing HTML block title and contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); @@ -42,9 +44,11 @@ class block_html_edit_form extends block_edit_form { $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'); + if (!empty($CFG->block_html_allowcssclasses)) { + $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) { diff --git a/blocks/html/lang/en/block_html.php b/blocks/html/lang/en/block_html.php index 6e82be80640..d331059e3f7 100644 --- a/blocks/html/lang/en/block_html.php +++ b/blocks/html/lang/en/block_html.php @@ -23,7 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['configclasses'] = 'Additional HTML classes'; +$string['allowadditionalcssclasses'] = 'Allow additional CSS classes'; +$string['configallowadditionalcssclasses'] = 'Adds a configuration option to HTML block instances allowing additional CSS classes to be set.'; +$string['configclasses'] = 'Additional CSS 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'; diff --git a/blocks/html/settings.php b/blocks/html/settings.php new file mode 100644 index 00000000000..59cb79760d5 --- /dev/null +++ b/blocks/html/settings.php @@ -0,0 +1,10 @@ +fulltree) { + $settings->add(new admin_setting_configcheckbox('block_html_allowcssclasses', get_string('allowadditionalcssclasses', 'block_html'), + get_string('configallowadditionalcssclasses', 'block_html'), 0)); +} + + -- 2.43.0