Commit 8b400358 authored by Nigel McNie's avatar Nigel McNie
Browse files

Make most blocktype titles editable.

This patch makes most blocktypes have no title set by default when created. For those that used to set their own titles, if no title is set after the configuration form is submitted, then they get the chance to set the title.

So for example, the RSS block will start with an empty title, but if the user doesn't set it, the title will be the title of the feed that is being syndicated.

Blocks like 'textbox' still keep their defaults, because they don't have any special case way of setting their own titles.
parent fc57b81a
......@@ -29,4 +29,6 @@ defined('INTERNAL') || die();
$string['title'] = 'Blog';
$string['description'] = 'Display an entire blog';
$string['defaulttitledescription'] = 'If you leave this blank, the title of the blog will be used';
?>
......@@ -29,4 +29,6 @@ defined('INTERNAL') || die();
$string['title'] = 'Blog Post';
$string['description'] = 'Display one blog post';
$string['defaulttitledescription'] = 'If you leave this blank, the title of the blog post will be used';
?>
......@@ -29,4 +29,6 @@ defined('INTERNAL') || die();
$string['title'] = 'A Folder';
$string['description'] = 'A single folder from your Files area';
$string['defaulttitledescription'] = 'If you leave this blank, the title of the folder will be used';
?>
......@@ -32,13 +32,6 @@ class PluginBlocktypeEntireresume extends PluginBlocktype {
return get_string('title', 'blocktype.resume/entireresume');
}
/**
* Entire resume blocks never have titles
*/
public static function get_instance_title(BlockInstance $bi) {
return '';
}
public static function get_description() {
return get_string('description', 'blocktype.resume/entireresume');
}
......@@ -74,8 +67,15 @@ class PluginBlocktypeEntireresume extends PluginBlocktype {
return $smarty->fetch('blocktype:entireresume:content.tpl');
}
// Yes, we do have instance config. People are allowed to specify the title
// of the block, nothing else at this time. So in the next two methods we
// say yes and return no fields, so the title will be configurable.
public static function has_instance_config() {
return false;
return true;
}
public static function instance_config_form() {
return array();
}
// TODO: make decision on whether this should be abstract or not. PROBABLY SHOULD BE
......
......@@ -32,4 +32,6 @@ $string['description'] = 'Display any resumé information';
$string['fieldtoshow'] = 'Field to show';
$string['filloutyourresume'] = '%sFill out your resumé%s in order to add more fields!';
$string['defaulttitledescription'] = 'If you leave this blank, the name of the field will be used';
?>
......@@ -35,4 +35,5 @@ $string['showfeeditemsinfulldesc'] = 'Whether to show a summary of the feed item
$string['invalidurl'] = 'That URL is invalid. You can only view feeds for http and https URLs.';
$string['invalidfeed'] = 'The feed appears to be invalid. The error reported was: %s';
$string['lastupdatedon'] = 'Last updated on %s';
$string['defaulttitledescription'] = 'If you leave this blank, the title of the feed will be used';
?>
......@@ -269,8 +269,8 @@ class BlockInstance {
$this->set('configdata', $values);
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if (method_exists($blocktypeclass, 'get_instance_title')) {
// Get the explicitly set instance title
if (!$title && $title !== '0' && method_exists($blocktypeclass, 'get_instance_title')) {
// Get the default title for the block if one isn't set
$title = call_static_method($blocktypeclass, 'get_instance_title', $this);
}
......@@ -416,23 +416,33 @@ class BlockInstance {
$elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this);
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
if (method_exists($blocktypeclass, 'get_instance_title')) {
// Get the explicitly set instance title
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 {
// Use the blocktype title as a default
// 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 = array_merge(
array(
'title' => array(
'type' => 'text',
'title' => 'Block Title',
'defaultvalue' => $this->get('title')
'title' => get_string('blocktitle', 'view'),
'description' => (method_exists($blocktypeclass, 'get_instance_title'))
? get_string('defaulttitledescription', 'blocktype.' . blocktype_name_to_namespaced($this->get('blocktype'))) : null,
'defaultvalue' => $title,
),
),
$elements
);
}
if ($new) {
$cancel = get_string('remove');
......
......@@ -189,6 +189,7 @@ $string['moveblockup'] = 'Move this block up';
$string['moveblockright'] = 'Move this block right';
$string['configureblock'] = 'Configure this block';
$string['removeblock'] = 'Remove this block';
$string['blocktitle'] = 'Block Title';
$string['changemyviewlayout'] = 'Change My View Layout';
$string['viewcolumnspagedescription'] = 'First, select the number of columns in your View. In the next step, you will be able to change the widths of the columns.';
......
......@@ -915,6 +915,30 @@ function blocktype_single_to_namespaced($blocktype, $artefact='') {
return $artefact . '/' . $blocktype;
}
/**
* Given a blocktype name, convert it to the namespaced version.
*
* This will be $artefacttype/$blocktype, or just plain $blocktype for system
* blocktypes.
*
* This is useful for language strings
*/
function blocktype_name_to_namespaced($blocktype) {
static $resultcache = array();
if (!isset($resultcache[$blocktype])) {
$artefactplugin = get_field('blocktype_installed', 'artefactplugin', 'name', $blocktype);
if ($artefactplugin) {
$resultcache[$blocktype] = "$artefactplugin/$blocktype";
}
else {
$resultcache[$blocktype] = $blocktype;
}
}
return $resultcache[$blocktype];
}
/**
* Fires an event which can be handled by different parts of the system
......
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