Commit d9c1560b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Hide title in block config form for autogenerated block titles

When block titles are empty and the block can generate its own title,
hide the title field in the configure form and add a link to expand it.
Don't rely on block title being != blocktype title to determine whether
the block title has been edited, because changing languages breaks this.

Change-Id: I173ff76176461db1ce24ad8e46d84a1783cb6dee
Signed-off-by: default avatarRichard Mansfield <>
parent de3d7304
......@@ -726,34 +726,30 @@ class BlockInstance {
safe_require('blocktype', $this->get('blocktype'));
$elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this, $this->get_view()->get('template'));
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if ($this->get('title') != call_static_method($blocktypeclass, 'get_title')) {
// If the title for this block has been set to something other than
// the block title, use it unconditionally
$title = $this->get('title');
else if (method_exists($blocktypeclass, 'get_instance_title')) {
// Block types can specify a default title for a block
$title = call_static_method($blocktypeclass, 'get_instance_title', $this);
else {
// A block that doesn't have a method for setting an instance
// title, and hasn't had its title changed (e.g. a new textbox)
$title = $this->get('title');
$elements = call_static_method($blocktypeclass, 'instance_config_form', $this, $this->get_view()->get('template'));
// @todo: If we know the title is going to be overridden in override_instance_title(),
// hide or disable the title field in the form. Currently not a problem, because the
// blocktypes that override the instance title don't have configurable instances.
// Maybe just remove or simplify title in the elements list below and make all the
// blocktype classes pass the title element in their instance_config_form().
// Block types may specify a method to generate a default title for a block
$hasdefault = method_exists($blocktypeclass, 'get_instance_title');
$title = $this->get('title');
$elements = array_merge(
'title' => array(
'type' => 'text',
'title' => get_string('blocktitle', 'view'),
'description' => (method_exists($blocktypeclass, 'get_instance_title'))
? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null,
'description' => $hasdefault ? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null,
'defaultvalue' => $title,
'rules' => array('maxlength' => 255),
'hidewhenempty' => $hasdefault,
'expandtext' => get_string('setblocktitle'),
'blockconfig' => array(
'type' => 'hidden',
......@@ -929,4 +929,6 @@ $string['findfriendslinked'] = 'Find <a href="%s">Friends</a>';
$string['joingroups'] = 'Join <a href="%s">Groups</a>';
$string['sharenetworkdescription'] = '<br>Control your privacy.';
$string['howtodisable'] = 'You have hidden the information box. You can control its visibility in <a href="%s">Settings</a>.';
// Blocktype
$string['setblocktitle'] = 'Set a block title';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment