Commit f5f09954 authored by Nigel McNie's avatar Nigel McNie
Browse files

Rationalise the behaviour of copying blogs.

If a blog or post is put into a View via reference, you now can't
configure that block (other than to change its title). There is a note
that points out the block has been copied, which explains this for
users.

Fixed up a couple of other problems with the blocktype configuration
forms, which should hopefully mean users won't see options they can't
use.
parent 45dd55eb
......@@ -82,16 +82,38 @@ class PluginBlocktypeBlog extends PluginBlocktype {
}
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// No configuration when this block is in a template
return array();
}
global $USER;
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blog'),
);
if (!empty($configdata['artefactid'])) {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
}
$elements = array();
// If the blog in this block is owned by the owner of the View, then
// the block can be configured. Otherwise, the blog was copied in from
// another View. We won't confuse users by asking them to choose a blog
// to put in this block, when the one that is currently in it isn't
// choosable.
//
// Note: the owner check will have to change when we do group/site
// blogs
if (empty($configdata['artefactid']) || $blog->get('owner') == $USER->get('id')) {
$elements[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate);
if ($istemplate) {
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blog');
};
}
else {
$elements[] = array(
'type' => 'html',
'name' => 'notice',
'value' => '<div class="message">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blog', 'artefact.blog')) . '</div>',
);
}
return $elements;
}
/**
......@@ -131,20 +153,23 @@ class PluginBlocktypeBlog extends PluginBlocktype {
}
public static function artefactchooser_element($default=null, $istemplate=false) {
return array(
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('blog', 'artefact.blog'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'blog',
'limit' => 10,
'selectone' => true,
'artefacttypes' => array('blog'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
);
if (!$istemplate) {
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
......
......@@ -110,33 +110,58 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
}
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// No configuration when this block is in a template
return array();
}
global $USER;
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'),
);
if (!empty($configdata['artefactid'])) {
$blog = $instance->get_artefact_instance($configdata['artefactid']);
}
$elements = array();
// If the blog post in this block is owned by the owner of the View,
// then the block can be configured. Otherwise, the blog post was
// copied in from another View. We won't confuse users by asking them to
// choose a blog post to put in this block, when the one that is
// currently in it isn't choosable.
//
// Note: the owner check will have to change when we do group/site
// blogs
if (empty($configdata['artefactid']) || $blog->get('owner') == $USER->get('id')) {
$elements[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate);
if ($istemplate) {
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost');
};
}
else {
$elements[] = array(
'type' => 'html',
'name' => 'notice',
'value' => '<div class="message">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>',
);
}
return $elements;
}
public static function artefactchooser_element($default=null, $istemplate=false) {
return array(
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('blogpost', 'artefact.blog'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'blogpost',
'limit' => 10,
'selectone' => true,
'artefacttypes' => array('blogpost'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
);
if (!$istemplate) {
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
......
......@@ -37,6 +37,7 @@ $string['attach'] = 'Attach';
$string['attachedfilelistloaded'] = 'Attached file list loaded';
$string['attachedfiles'] = 'Attached files';
$string['attachments'] = 'Attachments';
$string['blogcopiedfromanotherview'] = 'Note: This block has been copied from another View. You may move it around or remove it, but you cannot change what %s is in it.';
$string['blogdesc'] = 'Description';
$string['blogdescdesc'] = 'e.g., ‘A record of Jill\'s experiences and reflections’.';
$string['blogdoesnotexist'] = 'You are trying to access a blog that does not exist';
......
Supports Markdown
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