Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Blocks: Difference between revisions

From MoodleDocs
(moodle 2 code for customizing block's title)
Line 1: Line 1:
This page is for reporting errors, suggesting improvements, etc. Feel free to contribute!
{{Moodle 2.0}}


== "Notifications" ==
== The Specialists ==


At this part: "At this point our block should be capable of being automatically installed in Moodle and added to courses; visit your administration page to install it and after seeing it in action come back to continue our tutorial."
To customize the block's title under Moodle 2.0 the following code can be used:


This is not clear since Moodle no longer has a single administration page.
edit_form.php


More to the point would say to go to the /admin/index.php page for your Moodle install. On my latest version of Moodle 1.8 the link in the Administration block is labeled "Notifications".
<code php>
    $mform->addElement('text', 'config_title', get_string('configtitle', 'block_simplehtml'));
    $mform->setDefault('config_text', get_string('simplehtml', 'block_simplehtml'));
    $mform->setType('config_title', PARAM_MULTILANG);
</code>


== Splitting up ==
simplehtml/lang/en/block_simplehtml.php


I split the page up into sub pages because I got an error message that the page was over 32 KB. The three appendixes are now separate pages. --[[User:Frank Ralf|Frank Ralf]] 12:16, 26 January 2009 (CST)
<code php>
  $string['configtitle'] = 'Title of simple html';
</code>


== Increasing readability ==
block_simplehtml.php
* Colored the code
* Inserted some line breaks
* Amended the appendixes --[[User:Frank Ralf|Frank Ralf]] 16:24, 6 February 2009 (CST)
* Started correcting the old links (Blocks_howto) --[[User:Frank Ralf|Frank Ralf]] 16:24, 6 February 2009 (CST)


== New new settings.php method ==
<code php>
There is a new settings.php method to do this, I don't know that much about it, so could someone who does change this page please?--[[User:Mike Worth|Mike Worth]] 05:01, 28 January 2009 (CST)
  function specialization() {
    $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('simplehtml', 'block_simplehtml'));
    }
</code>


: When was this feature added? I'm having issues with my block with seemingly multiple Moodle 1.9 installs not being able to display the settings page. Could we have '''any''' documentation on this?--[[User:Jonathan Doane|Jonathan Doane]] 13:26, 30 August 2010 (EST)
The specialization function is copied from the html block. Different standard blocks seem to implement this differently. It would be nice if someone can explain what's happening in this specialization function.


:: See [[User_talk:Frank_Ralf/Experience_of_converting_a_module_to_Moodle_2]] for an example. --[[User:Frank Ralf|Frank Ralf]] 19:40, 16 November 2010 (UTC)
--[[User:Roel Cantada|Roel Cantada]] 11:43, 7 July 2011 (WST)
 
== block_simplehtml ==
 
* I had to title my first file block_simplehtml.php to get it to install. Is this always true?
* For answer see [[User talk:Colin Matheson]]. --[[User:Frank Ralf|Frank Ralf]] 08:54, 1 March 2009 (CST)
 
== get_config() ?? ==
 
No mention of get_config() anywhere? {{Unsigned|Jeffrey Silverman}}
: Thanks for the hint, Jeffrey! Will be added to the TODO list. For the time being I added some direct links to http://xref.moodle.org on [[Guidelines_for_contributed_code#Does_the_code_use_the_config_plugins_table.3F]] (Please sign your comments.) --[[User:Frank Ralf|Frank Ralf]] 10:03, 29 March 2009 (UTC)
 
== How to set Strings (Language) ==
 
Maybe nice to have: A link or description how to set Language-Strings for the block_simplehtml.
{{Unsigned|Jan Roth}}
: Hi Jan, please have a look at [http://dev.moodle.org/mod/resource/view.php?id=48  Moodle Programming > Unit 7 - Part A - Block Basics] which is sort of a follow-up to this docs. And you will find additional information at [[Places to search for lang strings]]. And please sign your comments - second button from the right ;-) --[[User:Frank Ralf|Frank Ralf]] 14:43, 19 January 2010 (UTC)
 
== Element names ==
 
Apparently, element names inside a specific_definition form have to start with "config_", I was lucky that I figure this out, it isn't documented anywhere.
--[[User:Jay Knight|Jay Knight]] 22:12, 7 March 2011 (UTC)

Revision as of 03:43, 7 July 2011

Moodle 2.0


The Specialists

To customize the block's title under Moodle 2.0 the following code can be used:

edit_form.php

   $mform->addElement('text', 'config_title', get_string('configtitle', 'block_simplehtml'));
   $mform->setDefault('config_text', get_string('simplehtml', 'block_simplehtml'));
   $mform->setType('config_title', PARAM_MULTILANG);

simplehtml/lang/en/block_simplehtml.php

 $string['configtitle'] = 'Title of simple html';

block_simplehtml.php

 function specialization() {
   $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('simplehtml', 'block_simplehtml'));
   }

The specialization function is copied from the html block. Different standard blocks seem to implement this differently. It would be nice if someone can explain what's happening in this specialization function.

--Roel Cantada 11:43, 7 July 2011 (WST)