Code error with the documentation.

Code error with the documentation.

by Oomeeth Persad -
Number of replies: 0

Hello!

I have recently come across an error on the page: https://docs.moodle.org/dev/Blocks under 'The Specialists'.

The error is with the block of code:

public function specialization() {
    if (isset($this->config)) {

        if (empty($this->config->title)) {

            $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');

        }    

    }

}

The problem with this piece of code is that it does not update the content of the custom block in the above example. To prevent any confusion, the specialization function should look like this:

public function specialization() {
    if (isset($this->config)) {

        if (empty($this->config->title)) {

            $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');

        } else {

            $this->content->text = $this->config->text;

        }    

    }

}

Average of ratings: -