Skip to content

Commit

Permalink
MDL-35042 blocks: Allow HTML block advanced setting to be toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Barnes committed Aug 24, 2012
1 parent d71c486 commit 055cc83
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
12 changes: 10 additions & 2 deletions blocks/html/block_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function init() {
$this->title = get_string('pluginname', 'block_html');
}

function has_config() {
return true;
}

function applicable_formats() {
return array('all' => true);
}
Expand Down Expand Up @@ -138,10 +142,14 @@ public function instance_can_be_docked() {
* @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;
Expand Down
10 changes: 7 additions & 3 deletions blocks/html/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -42,9 +44,11 @@ protected function specific_definition($mform) {
$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) {
Expand Down
4 changes: 3 additions & 1 deletion blocks/html/lang/en/block_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions blocks/html/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

defined('MOODLE_INTERNAL') || die;

if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('block_html_allowcssclasses', get_string('allowadditionalcssclasses', 'block_html'),
get_string('configallowadditionalcssclasses', 'block_html'), 0));
}


0 comments on commit 055cc83

Please sign in to comment.