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

Add docs about the difference between Blocktype::allowed_in_view and

Blockinstance->allowed_in_view.

Fixed a couple of method calls in the meantime.
parent c00ec304
......@@ -848,7 +848,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
* blogposts but not the containing blog. We need to create a new
* blog to hold the copied posts.
*/
public function default_parent_for_copy(&$view, &$template) {
public function default_parent_for_copy(&$view, &$template, $artefactstoignore) {
static $blogid;
if (!empty($blogid)) {
......
......@@ -1368,10 +1368,6 @@ class ArtefactTypeImage extends ArtefactTypeFile {
. '" alt=""></a></div>' . $result['html'];
return $result;
}
public function default_parent_for_copy(&$view, &$template) {
return parent::default_parent_for_copy($view, $template);
}
}
class ArtefactTypeProfileIcon extends ArtefactTypeImage {
......@@ -1412,7 +1408,7 @@ class ArtefactTypeProfileIcon extends ArtefactTypeImage {
. ($artefact % 256) . '/' . $artefact);
}
public function default_parent_for_copy(&$view, &$template) {
public function default_parent_for_copy(&$view, &$template, $artefactstoignore) {
return null;
}
......
......@@ -167,7 +167,20 @@ abstract class PluginBlocktype extends Plugin {
foreach ($bts as $bt) {
$namespaced = blocktype_single_to_namespaced($bt->name, $bt->artefactplugin);
safe_require('blocktype', $namespaced);
if ($view->get('template') || call_static_method(generate_class_name('blocktype', $namespaced), 'allowed_in_view', $view)) {
// Note for later: this is Blocktype::allowed_in_view, which
// returns true if the blocktype should be insertable into the
// given view.
// e.g. for blogs it returns false when view owner is not set,
// because blogs can't be inserted into group views.
// This could be different from whether a blockinstance is allowed
// to be copied into a View (see the other place in this file where
// allowed_in_view is called)
//
// Note also that if we want templates to be able to have all
// blocktypes, we can add $view->get('template') here as part of
// the condition, and also to View::addblocktype and
// View::get_category_data
if (call_static_method(generate_class_name('blocktype', $namespaced), 'allowed_in_view', $view)) {
$blocktypes[] = array(
'name' => $bt->name,
'title' => call_static_method(generate_class_name('blocktype', $namespaced), 'get_title'),
......@@ -810,6 +823,11 @@ class BlockInstance {
$sameowner = ($viewowner['type'] == $templateowner['type'] && $viewowner['id'] == $templateowner['id']);
// Check to see if the block is allowed to be copied into the new View
//
// Note for later: this is Blockinstance->allowed_in_view. This
// determines whether this blockinstance should be copied into a view.
// This could be a different question from BlockType::allowed_in_view!
// But for now they use the same method.
if (!call_static_method($blocktypeclass, 'allowed_in_view', $view)) {
return false;
}
......
......@@ -699,7 +699,7 @@ class View {
$categories = array();
foreach (get_records_array('blocktype_installed_category') as $blocktypecategory) {
safe_require('blocktype', $blocktypecategory->blocktype);
if ($this->get('template') || call_static_method(generate_class_name("blocktype", $blocktypecategory->blocktype), "allowed_in_view", $this)) {
if (call_static_method(generate_class_name("blocktype", $blocktypecategory->blocktype), "allowed_in_view", $this)) {
if (!isset($categories[$blocktypecategory->category])) {
$categories[$blocktypecategory->category] = array(
'name' => $blocktypecategory->category,
......@@ -1080,7 +1080,7 @@ class View {
}
safe_require('blocktype', $values['blocktype']);
if (!$this->get('template') && !call_static_method(generate_class_name('blocktype', $values['blocktype']), 'allowed_in_view', $this)) {
if (!call_static_method(generate_class_name('blocktype', $values['blocktype']), 'allowed_in_view', $this)) {
throw new UserException('[translate] Cannot put ' . $values['blocktype'] . ' blocktypes into this view');
}
......
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