MDL-30340 blocks - hide some redundant pagetypepattern options at front page

The dual front-page/system-wide form to edit blocks can
be reduced asuming that, always:

A) system sets the context to system,
   recursively and with page-type set to "*"
B) frontpage only sets the context to site-course,
   non-recursively and with page-type set to "site-index"
C) frontpage all added sets the context to site-course,
   recursively and with paget-type set to "*"

And that is the change that this patch provides, by:

1) detecting properly if we are editing blocks @ protpage
2) passing that information to the form data processor
3) setting parentcontextid, showinsubcontexts and
   pagetypepattern following the A, B, C immutables above.

Finally, and affecting some other system-wide pages, there
are cases (my, user templates...) having only one possible
pagetypepattern, and it looks badly if the page has subpages, so
for those system-wide cases we are showing exceptionaly the
pagetypepattern statically. This will be revisited once MDL-30574
is decided and implemented, although perhaps it's ok to leave it
as default to places with only one pagetypepattern available.
This commit is contained in:
Eloy Lafuente (stronk7)
2011-12-05 01:09:02 +01:00
parent 9d2c424d83
commit d4e71a4eed
2 changed files with 105 additions and 50 deletions
+36 -22
View File
@@ -1227,35 +1227,49 @@ class block_manager {
$bi->subpagepattern = $data->bui_subpagepattern;
}
$parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
$parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
// Updating stickiness and contexts. See MDL-21375 for details.
if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination
// Explicitly set the context
// Explicitly set the default context
$bi->parentcontextid = $parentcontext->id;
// Should the block be sticky
if ($data->bui_contexts == BUI_CONTEXTS_ENTIRE_SITE or $data->bui_contexts == BUI_CONTEXTS_FRONTPAGE_SUBS) {
$bi->showinsubcontexts = true;
} else {
$bi->showinsubcontexts = false;
}
// If the block wants to be system-wide, then explicitly set that
if ($data->bui_contexts == BUI_CONTEXTS_ENTIRE_SITE) { // Only possible on a frontpage or system page
$bi->parentcontextid = $systemcontext->id;
} else { // The block doesn't want to be system-wide, so let's ensure that
if ($parentcontext->id == $systemcontext->id) { // We need to move it to the front page
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
$bi->parentcontextid = $frontpagecontext->id;
if ($data->bui_contexts == BUI_CONTEXTS_FRONTPAGE_ONLY) {
// If the front page only is specified, the page type setting is ignored
// as explicitely set to site-index
$bi->pagetypepattern = 'site-index';
// Perform some exceptions for system/frontpage data. MDL-30340
switch ($data->bui_contexts) {
case BUI_CONTEXTS_ENTIRE_SITE:
// it's a system-wide block. 100% guaranteed, set parentcontextid and showinsubcontexts
$bi->parentcontextid = $systemcontext->id;
$bi->showinsubcontexts = true;
// and also, if it's one edition @ frontpage, set its pagetypepattern to '*'
// it already arrives that way from the form, but just re-enforce it here
if ($data->bui_editingatfrontpage) {
$bi->pagetypepattern = '*';
}
}
break;
case BUI_CONTEXTS_FRONTPAGE_SUBS:
// it's a frontpage-wide (with subcontexts) block. 100% guaranteed, set parentcontextid and showinsubcontexts
$bi->parentcontextid = $frontpagecontext->id;
$bi->showinsubcontexts = true;
// and also, if it's one edition @ frontpage, set its pagetypepattern to '*'
// it already arrives that way from the form, but just re-enforce it here
if ($data->bui_editingatfrontpage) {
$bi->pagetypepattern = '*';
}
break;
case BUI_CONTEXTS_FRONTPAGE_ONLY:
// it's a frontpage-only (no subcontexts) block. 100% guaranteed, set parentcontextid and showinsubcontexts
$bi->parentcontextid = $frontpagecontext->id;
$bi->showinsubcontexts = false;
// and also, if it's one edition @ frontpage, set its pagetypepattern to 'site-index'
// it originally comes as '*' from the form, here we change that in proviosion of
// future 'site-index' pages
if ($data->bui_editingatfrontpage) {
$bi->pagetypepattern = 'site-index';
}
break;
}
}