Merge branch 'MDL-30585_21' of git://github.com/stronk7/moodle into MOODLE_21_STABLE

This commit is contained in:
Sam Hemelryk
2011-12-14 15:29:40 +13:00
4 changed files with 106 additions and 43 deletions
+12 -1
View File
@@ -35,5 +35,16 @@ function admin_page_type_list($pagetype, $parentcontext, $currentcontext) {
'admin-*' => get_string('page-admin-x', 'pagetype'),
$pagetype => get_string('page-admin-current', 'pagetype')
);
// Add the missing * (any page) option for them. MDL-30340
// TODO: These pages are really 'pagetype-varying' - MDL-30564 -
// and some day we should stop behaving that way, so proper pagetypes
// can be specified for it (like course-category-* or so).
// Luckly... the option we are introducing '*' is independent
// of that varying behavior, so will work.
if ($pagetype == 'admin-course-category') {
$array += array(
'*' => get_string('page-x', 'pagetype')
);
}
return $array;
}
}
+57 -20
View File
@@ -93,24 +93,44 @@ class block_edit_form extends moodleform {
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));
$mform->addHelpButton('bui_homecontext', 'createdat', 'block');
// For pre-calculated (fixed) pagetype lists
$pagetypelist = array();
// parse pagetype patterns
$bits = explode('-', $this->page->pagetype);
$contextoptions = array();
if ( ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID) ||
($parentcontext->contextlevel == CONTEXT_SYSTEM)) { // Home page
if ($bits[0] == 'tag' || $bits[0] == 'admin') {
// tag and admin pages always use system context
// the contexts options don't make differences, so we use
// page type patterns only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
} else {
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
}
// First of all, check if we are editing blocks @ front-page or no and
// make some dark magic if so (MDL-30340) because each page context
// implies one (and only one) harcoded page-type that will be set later
// when processing the form data at {@link block_manager::process_url_edit()}
// There are some conditions to check related to contexts
$ctxconditions = $this->page->context->contextlevel == CONTEXT_COURSE &&
$this->page->context->instanceid == get_site()->id;
// And also some pagetype conditions
$pageconditions = isset($bits[0]) && isset($bits[1]) && $bits[0] == 'site' && $bits[1] == 'index';
// So now we can be 100% sure if edition is happening at frontpage
$editingatfrontpage = $ctxconditions && $pageconditions;
// Let the form to know about that, can be useful later
$mform->addElement('hidden', 'bui_editingatfrontpage', (int)$editingatfrontpage);
// Front page, show the page-contexts element and set $pagetypelist to 'any page' (*)
// as unique option. Processign the form will do any change if needed
if ($editingatfrontpage) {
$contextoptions = array();
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
$pagetypelist['*'] = '*'; // This is not going to be shown ever, it's an unique option
// Any other system context block, hide the page-contexts element,
// it's always system-wide BUI_CONTEXTS_ENTIRE_SITE
} else if ($parentcontext->contextlevel == CONTEXT_SYSTEM) {
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
} else if ($parentcontext->contextlevel == CONTEXT_COURSE) {
// 0 means display on current context only, not child contexts
// but if course managers select mod-* as pagetype patterns, block system will overwrite this option
@@ -126,12 +146,10 @@ class block_edit_form extends moodleform {
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
}
$displaypagetypewarning = false;
if ($this->page->pagetype == 'site-index') { // No need for pagetype list on home page
$pagetypelist = array('*'=>get_string('page-x', 'pagetype'));
} else {
// Generate pagetype patterns by callbacks
// Generate pagetype patterns by callbacks if necessary (has not been set specifically)
if (empty($pagetypelist)) {
$pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
$displaypagetypewarning = false;
if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
// Pushing block's existing page type pattern
$pagetypestringname = 'page-'.str_replace('*', 'x', $this->block->instance->pagetypepattern);
@@ -156,6 +174,25 @@ class block_edit_form extends moodleform {
} else {
$value = array_pop(array_keys($pagetypelist));
$mform->addElement('hidden', 'bui_pagetypepattern', $value);
// Now we are really hiding a lot (both page-contexts and page-type-patterns),
// specially in some systemcontext pages having only one option (my/user...)
// so, until it's decided if we are going to add the 'bring-back' pattern to
// all those pages or no (see MDL-30574), we are going to show the unique
// element statically
// TODO: Revisit this once MDL-30574 has been decided and implemented, although
// perhaps it's not bad to always show this statically when only one pattern is
// available.
if (!$editingatfrontpage) {
// Try to beautify it
$strvalue = $value;
$strkey = 'page-'.str_replace('*', 'x', $strvalue);
if (get_string_manager()->string_exists($strkey, 'pagetype')) {
$strvalue = get_string($strkey, 'pagetype');
}
// Show as static (hidden has been set already)
$mform->addElement('static', 'bui_staticpagetypepattern',
get_string('restrictpagetypes','block'), $strvalue);
}
}
if ($this->page->subpage) {
+36 -18
View File
@@ -1062,9 +1062,6 @@ class block_manager {
/**
* Process any block actions that were specified in the URL.
*
* This can only be done given a valid $page object.
*
* @param moodle_page $page the page to add blocks to.
* @return boolean true if anything was done. False if not.
*/
public function process_url_actions() {
@@ -1231,28 +1228,42 @@ 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;
// If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not
$bi->showinsubcontexts = (int)(!empty($data->bui_contexts));
if ($data->bui_editingatfrontpage) { // The block is being edited on the front page
// 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;
$bi->showinsubcontexts = BUI_CONTEXTS_CURRENT_SUBS; //show in current and sub contexts
$bi->pagetypepattern = '*';
// The interface here is a special case because the pagetype pattern is
// totally derived from the context menu. Here are the excpetions. MDL-30340
} 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;
$bi->pagetypepattern = 'site-index';
switch ($data->bui_contexts) {
case BUI_CONTEXTS_ENTIRE_SITE:
// The user wants to show the block across the entire site
$bi->parentcontextid = $systemcontext->id;
$bi->showinsubcontexts = true;
$bi->pagetypepattern = '*';
break;
case BUI_CONTEXTS_FRONTPAGE_SUBS:
// The user wants the block shown on the front page and all subcontexts
$bi->parentcontextid = $frontpagecontext->id;
$bi->showinsubcontexts = true;
$bi->pagetypepattern = '*';
break;
case BUI_CONTEXTS_FRONTPAGE_ONLY:
// The user want to show the front page on the frontpage only
$bi->parentcontextid = $frontpagecontext->id;
$bi->showinsubcontexts = false;
$bi->pagetypepattern = 'site-index';
// This is the only relevant page type anyway but we'll set it explicitly just
// in case the front page grows site-index-* subpages of its own later
break;
}
}
}
@@ -1663,6 +1674,13 @@ function generate_page_type_patterns($pagetype, $parentcontext = null, $currentc
$patterns = default_page_type_list($pagetype, $parentcontext, $currentcontext);
}
// Ensure that the * pattern is always available if editing block 'at distance', so
// we always can 'bring back' it to the original context. MDL-30340
if ($currentcontext->id != $parentcontext->id && !isset($patterns['*'])) {
// TODO: We could change the string here, showing its 'bring back' meaning
$patterns['*'] = get_string('page-x', 'pagetype');
}
return $patterns;
}
@@ -1703,7 +1721,7 @@ function default_page_type_list($pagetype, $parentcontext = null, $currentcontex
* @return array
*/
function my_page_type_list($pagetype, $parentcontext = null, $currentcontext = null) {
return array('my-index' => 'my-index');
return array('my-index' => get_string('page-my-index', 'pagetype'));
}
/**
+1 -4
View File
@@ -356,8 +356,5 @@ function user_get_user_details($user, $course = null) {
* @param stdClass $currentcontext Current context of block
*/
function user_page_type_list($pagetype, $parentcontext, $currentcontext) {
return array(
'user-profile'=>get_string('page-user-profile', 'pagetype'),
'my-index'=>get_string('page-my-index', 'pagetype')
);
return array('user-profile'=>get_string('page-user-profile', 'pagetype'));
}