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

(#3063) Make blocktype configuration forms change if they are in a template.

Now they do things like not making it compulsory to choose an artefact
if it's a template (as the creator might just want to put the block
there), and removing some options that only make sense in Views.

There's a parameter for instance_config_form and artefactchooser_element
to allow the Blocktype to detemine whether it's in a template easily.
parent 582c19e2
......@@ -81,11 +81,15 @@ class PluginBlocktypeBlog extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// No configuration when this block is in a template
return array();
}
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blog'),
);
}
......@@ -126,7 +130,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
return $artefacts;
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
return array(
'name' => 'artefactid',
'type' => 'artefactchooser',
......
......@@ -109,16 +109,20 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// No configuration when this block is in a template
return array();
}
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'),
);
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
return array(
'name' => 'artefactid',
'type' => 'artefactchooser',
......
......@@ -79,16 +79,20 @@ class PluginBlocktypeRecentposts extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// No configuration when this block is in a template
return array();
}
safe_require('artefact', 'blog');
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null),
self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $istemplate),
PluginArtefactBlog::block_advanced_options_element($configdata, 'blog'),
);
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
return array(
'name' => 'artefactids',
'type' => 'artefactchooser',
......
......@@ -101,28 +101,32 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null),
self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $istemplate),
);
}
public static function artefactchooser_element($default=null) {
return array(
public static function artefactchooser_element($default=null, $istemplate=false) {
$element = array(
'name' => 'artefactids',
'type' => 'artefactchooser',
'title' => get_string('Files', 'blocktype.file/filedownload'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'filedownload',
'limit' => 10,
'selectone' => false,
'artefacttypes' => array('file', 'image', 'profileicon'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
......
......@@ -81,27 +81,31 @@ class PluginBlocktypeFolder extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
);
}
public static function artefactchooser_element($default=null) {
return array(
public static function artefactchooser_element($default=null, $istemplate=false) {
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('folder', 'artefact.file'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'folder',
'limit' => 10,
'artefacttypes' => array('folder'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a folder if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
......
......@@ -62,10 +62,10 @@ class PluginBlocktypeHtml extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
);
}
......@@ -73,25 +73,28 @@ class PluginBlocktypeHtml extends PluginBlocktype {
return array('html', 'htm');
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
$extraselect = '(' . implode(' OR ', array_map(
create_function('$a', 'return "title LIKE \'%.$a\'";'),
self::get_allowed_extensions())
) . ')';
return array(
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('file', 'artefact.file'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'html',
'limit' => 10,
'artefacttypes' => array('file'),
'template' => 'artefact:file:artefactchooser-element.tpl',
'extraselect' => $extraselect,
);
if (!$istemplate) {
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
public static function get_viewtypes() {
......
......@@ -86,10 +86,10 @@ class PluginBlocktypeImage extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
return array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
'showdescription' => array(
'type' => 'checkbox',
'title' => get_string('showdescription', 'blocktype.file/image'),
......@@ -109,20 +109,24 @@ class PluginBlocktypeImage extends PluginBlocktype {
);
}
public static function artefactchooser_element($default=null) {
return array(
public static function artefactchooser_element($default=null, $istemplate=false) {
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('image'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'image',
'limit' => 10,
'artefacttypes' => array('image', 'profileicon'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
......
......@@ -79,10 +79,10 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
$form = array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null),
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
);
$form['width'] = array(
'type' => 'text',
......@@ -107,7 +107,7 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
return false;
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
$extraselect = 'filetype IN (' . join(',', array_map('db_quote', self::get_allowed_mimetypes())) . ')';
$extrajoin = ' JOIN {artefact_file_files} ON artefact_file_files.artefact = a.id ';
......@@ -116,9 +116,6 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
'type' => 'artefactchooser',
'title' => get_string('media', 'blocktype.file/internalmedia'),
'defaultvalue' => $default,
'rules' => array(
'required' => true,
),
'blocktype' => 'internalmedia',
'limit' => 5,
'selectone' => true,
......@@ -127,6 +124,13 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
'extrajoin' => $extrajoin,
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
public static function artefactchooser_get_element_data($artefact) {
......
......@@ -80,7 +80,12 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// Don't offer any configuration. Profile data needs to be reworked
// so it's not artefacts before this will work
return array();
}
$configdata = $instance->get('configdata');
$form = array();
......@@ -113,13 +118,13 @@ class PluginBlocktypeContactinfo extends PluginBlocktype {
);
// Which fields does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $istemplate);
return $form;
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
safe_require('artefact', 'internal');
return array(
'name' => 'artefactids',
......
......@@ -114,13 +114,18 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
// Don't offer any configuration. Profile data needs to be reworked
// so it's not artefacts before this will work
return array();
}
$configdata = $instance->get('configdata');
$form = array();
// Which fields does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null);
$form[] = self::artefactchooser_element((isset($configdata['artefactids'])) ? $configdata['artefactids'] : null, $istemplate);
// Profile icon
if (!$result = get_records_sql_array('SELECT a.id, a.artefacttype, a.title, a.note
......@@ -179,8 +184,7 @@ class PluginBlocktypeProfileinfo extends PluginBlocktype {
return $form;
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
safe_require('artefact', 'internal');
return array(
'name' => 'artefactids',
......
......@@ -82,8 +82,7 @@ class PluginBlocktypeEntireresume extends PluginBlocktype {
return array();
}
// TODO: make decision on whether this should be abstract or not. PROBABLY SHOULD BE
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
}
/**
......
......@@ -82,13 +82,16 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
return true;
}
public static function instance_config_form($instance) {
public static function instance_config_form($instance, $istemplate) {
if ($istemplate) {
return array();
}
$configdata = $instance->get('configdata');
$form = array();
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate);
$form['message'] = array(
'type' => 'html',
'value' => get_string('filloutyourresume', 'blocktype.resume/resumefield', '<a href="' . get_config('wwwroot') . 'artefact/resume/">', '</a>'),
......@@ -103,7 +106,7 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $istemplate=false) {
safe_require('artefact', 'resume');
return array(
'name' => 'artefactid',
......
......@@ -86,8 +86,9 @@ abstract class PluginBlocktype extends Plugin {
* blocktype that the form is for.
*
* @param mixed $default The default value for the element
* @param boolean $istemplate Whether the View this block is in is a template
*/
public static abstract function artefactchooser_element($default=null);
public static abstract function artefactchooser_element($default=null, $istemplate=false);
/**
* subclasses can override this if they need to do something a bit special
......@@ -256,7 +257,7 @@ abstract class SystemBlockType extends PluginBlockType {
return array();
}
public final static function artefactchooser_element($default=null) {
public final static function artefactchooser_element($default=null, $istemplate=false) {
}
}
......@@ -515,7 +516,7 @@ class BlockInstance {
}
safe_require('blocktype', $this->get('blocktype'));
$elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this);
$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')) {
......
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