How to set labels in custom fields in Configuring a Block? (I named it simplehtml). It's from the official Moodle Block tutorial that is for Moodle 2.0+. I am using the 3.4 version.
In my output below I have two labels blockstring and blocktitle, that I suppose to be placeholders to be set in /simplehtml/lang/en/block_simplehtml.php, but I could not figure out how to do it. I need some help.
And here is the code that matters:
edit_form.php
<?php
class block_simplehtml_edit_form extends block_edit_form {
protected function specific_definition($mform) {
$mform->addElement('header', 'config_header', get_string('blocksettings', 'block'));
$mform->addElement('text', 'config_text', get_string('blockstring', 'block_simplehtml'));
$mform->setDefault('config_text', 'default value');
$mform->setType('config_text', PARAM_RAW);
$mform->addElement('text', 'config_title', get_string('blocktitle', 'block_simplehtml'));
$mform->setDefault('config_title', 'default title value');
$mform->setType('config_title', PARAM_RAW);
}
}
block_simplehtml.php
<?php
class block_simplehtml extends block_base {
public function init() {
$this->title = get_string('simplehtml', 'block_simplehtml');
}
public function get_content() {
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
if (! empty($this->config->text)) {
$this->content->text = $this->config->text;
}
$this->content->footer = 'Footer here...';
return $this->content;
}
public function specialization() {
if (isset($this->config)) {
//$this->title = get_string('defaulttitle', 'block_simplehtml');
} else {
$this->title = $this->config->title;
}
if (empty($this->config->text)) {
$this->config->text = get_string('defaulttext', 'block_simplehtml');
}
}
}
lang/en/block_simplehtml.php
<?php
$string['pluginname'] = 'Simple HTML block';
$string['simplehtml'] = 'Simple HTML';
$string['simplehtml:addinstance'] = 'Add a new simple HTML block';
$string['simplehtml:myaddinstance'] = 'Add a new simple HTML block to My Moodle page';