Commit d4976c32 authored by Francois Marier's avatar Francois Marier
Browse files

Enforce the single_only() response from blocktypes

If a block is designed to only appear once per view, an error message will be
displayed when users try to add a second one to a given view.
parent b28cec50
......@@ -73,6 +73,7 @@ $string['blocktypeprovidedbyartefactnotinstallable'] = 'This will be installed a
$string['blockconfigdatacalledfromset'] = 'Configdata should not be set directly, use PluginBlocktype::instance_config_save instead';
$string['invaliddirection'] = 'Invalid direction %s';
$string['onlyoneprofileviewallowed'] = 'You are only allowed one profile view';
$string['onlyoneblocktypeperview'] = 'Cannot put more than one %s blocktype into a view';
// if you change these next two , be sure to change them in libroot/errors.php
// as they are duplicated there, in the case that get_string was not available.
......@@ -1148,6 +1148,14 @@ class View {
throw new UserException('[translate] Cannot put ' . $values['blocktype'] . ' blocktypes into this view');
if (call_static_method(generate_class_name('blocktype', $values['blocktype']), 'single_only', $this)) {
$count = count_records_select('block_instance', "view = ? AND blocktype = ?",
array($this->id, $values['blocktype']));
if ($count > 0) {
throw new UserException(get_string('onlyoneblocktypeperview', 'error', $values['blocktype']));
$bi = new BlockInstance(0,
'blocktype' => $values['blocktype'],
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