Skip to content

Commit b1627a9

Browse files
Dongsheng Caiandyjdavis
Dongsheng Cai
authored andcommitted
MDL-26105 Block settings should contains less options, and be more user friendly
AMOS BEGIN MOV [page-blog-index, pagetype], [page-blog-index, blog] MOV [page-blog-x, pagetype], [page-blog-x, blog] MOV [page-tag-x, pagetype], [page-tag-x, tag] MOV [page-course-view-weeks, pagetype], [page-course-view-weeks, format_weeks] MOV [page-course-view-weeks-x, pagetype], [page-course-view-weeks-x, format_weeks] MOV [page-course-view-topics, pagetype], [page-course-view-topics, format_topics] MOV [page-course-view-topics-x, pagetype], [page-course-view-topics-x, format_topics] AMOS END
1 parent a56c68e commit b1627a9

File tree

54 files changed

+570
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+570
-38
lines changed

blocks/edit_form.php

+59-23
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333

3434
require_once($CFG->libdir . '/formslib.php');
35+
require_once($CFG->libdir . '/blocklib.php');
3536

3637
/**
3738
* The base class form used by blocks/edit.php to edit block instance configuration.
@@ -89,40 +90,73 @@ function definition() {
8990
$parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
9091
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
9192

93+
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));
94+
$mform->addHelpButton('bui_homecontext', 'createdat', 'block');
95+
96+
// parse pagetype patterns
97+
$bits = explode('-', $this->page->pagetype);
98+
9299
$contextoptions = array();
93100
if ( ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID) ||
94-
($parentcontext->contextlevel == CONTEXT_SYSTEM)) { // Home page
95-
$contextoptions[0] = get_string('showonfrontpageonly', 'block');
96-
$contextoptions[1] = get_string('showonfrontpageandsubs', 'block');
97-
$contextoptions[2] = get_string('showonentiresite', 'block');
101+
($parentcontext->contextlevel == CONTEXT_SYSTEM)) { // Home page
102+
if ($bits[0] == 'tag') {
103+
// tag always use system context, the contexts options don't make differences, so we use
104+
// page type patterns only
105+
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
106+
} else {
107+
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
108+
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
109+
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
110+
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
111+
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
112+
}
113+
} else if ($parentcontext->contextlevel == CONTEXT_COURSE) {
114+
// 0 means display on current context only, not child contexts
115+
// but if course managers select mod-* as pagetype patterns, block system will overwrite this option
116+
// to 1 (display on current context and child contexts)
117+
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
118+
} else if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
119+
// module context doesn't have child contexts, so display in current context only
120+
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
98121
} else {
99122
$parentcontextname = print_context_name($parentcontext);
100-
$contextoptions[0] = get_string('showoncontextonly', 'block', $parentcontextname);
101-
$contextoptions[1] = get_string('showoncontextandsubs', 'block', $parentcontextname);
123+
$contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
124+
$contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
125+
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
102126
}
103-
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
104127

105128
if ($this->page->pagetype == 'site-index') { // No need for pagetype list on home page
106-
$pagetypelist = array('*');
129+
$pagetypelist = array('*'=>get_string('page-x', 'pagetype'));
107130
} else {
108-
$pagetypelist = matching_page_type_patterns($this->page->pagetype);
109-
}
110-
$pagetypeoptions = array();
111-
foreach ($pagetypelist as $pagetype) { // Find human-readable names for the pagetypes
112-
$pagetypeoptions[$pagetype] = $pagetype;
113-
$pagetypestringname = 'page-'.str_replace('*', 'x',$pagetype); // Better names MDL-21375
114-
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
115-
$pagetypeoptions[$pagetype] .= ' (' . get_string($pagetypestringname, 'pagetype') . ')';
131+
// Generate pagetype patterns by callbacks
132+
$pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
133+
if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
134+
// Pushing block's existing page type pattern
135+
$pagetypestringname = 'page-'.str_replace('*', 'x', $this->block->instance->pagetypepattern);
136+
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
137+
$pagetyelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
138+
}
116139
}
117140
}
118-
$mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypeoptions);
141+
142+
// hide page type pattern select box if there is only one choice
143+
if (count($pagetypelist) > 1) {
144+
$mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist);
145+
} else {
146+
$value = array_pop(array_keys($pagetypelist));
147+
$mform->addElement('hidden', 'bui_pagetypepattern', $value);
148+
}
119149

120150
if ($this->page->subpage) {
121-
$subpageoptions = array(
122-
'%@NULL@%' => get_string('anypagematchingtheabove', 'block'),
123-
$this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage),
124-
);
125-
$mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
151+
if ($parentcontext->contextlevel == CONTEXT_USER) {
152+
$mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%');
153+
} else {
154+
$subpageoptions = array(
155+
'%@NULL@%' => get_string('anypagematchingtheabove', 'block'),
156+
$this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage),
157+
);
158+
$mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
159+
}
126160
}
127161

128162
$defaultregionoptions = $regionoptions;
@@ -131,8 +165,10 @@ function definition() {
131165
$defaultregionoptions[$defaultregion] = $defaultregion;
132166
}
133167
$mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
168+
$mform->addHelpButton('bui_defaultregion', 'defaultregion', 'block');
134169

135170
$mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
171+
$mform->addHelpButton('bui_defaultweight', 'defaultweight', 'block');
136172

137173
// Where this block is positioned on this page.
138174
$mform->addElement('header', 'whereheader', get_string('onthispage', 'block'));
@@ -182,7 +218,7 @@ function set_data($defaults) {
182218

183219
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
184220
if ($defaults->parentcontextid == $systemcontext->id) {
185-
$defaults->bui_contexts = 2; // System-wide and sticky
221+
$defaults->bui_contexts = BUI_CONTEXTS_ENTIRE_SITE; // System-wide and sticky
186222
} else {
187223
$defaults->bui_contexts = $defaults->bui_showinsubcontexts;
188224
}

blog/lib.php

+15
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,18 @@ function blog_comment_validate($comment_param) {
10281028
}
10291029
return true;
10301030
}
1031+
1032+
/**
1033+
* Return a list of page types
1034+
* @param string $pagetype current page type
1035+
* @param stdClass $parentcontext Block's parent context
1036+
* @param stdClass $currentcontext Current context of block
1037+
*/
1038+
function blog_pagetypelist($pagetype, $parentcontext, $currentcontext) {
1039+
return array(
1040+
'*'=>get_string('page-x', 'pagetype'),
1041+
'blog-*'=>get_string('page-blog-x', 'blog'),
1042+
'blog-index'=>get_string('page-blog-index', 'blog'),
1043+
'blog-edit'=>get_string('page-blog-edit', 'blog')
1044+
);
1045+
}

course/format/topics/lang/en/format_topics.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525

2626
$string['sectionname'] = 'Topic';
2727
$string['pluginname'] = 'Topics format';
28-
$string['section0name'] = 'General';
28+
$string['section0name'] = 'General';
29+
$string['page-course-view-topics'] = 'Any course main page in topics format';
30+
$string['page-course-view-topics-x'] = 'Any course page in topics format';

course/format/weeks/lang/en/format_weeks.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@
2626
$string['sectionname'] = 'Week';
2727
$string['pluginname'] = 'Weekly format';
2828
$string['section0name'] = 'General';
29+
$string['page-course-view-weeks'] = 'Any course main page in weeks format';
30+
$string['page-course-view-weeks-x'] = 'Any course page in weeks format';

course/lib.php

+20
Original file line numberDiff line numberDiff line change
@@ -4211,3 +4211,23 @@ protected function notify($touser, $fromuser, $name='courserequested', $subject,
42114211
message_send($eventdata);
42124212
}
42134213
}
4214+
4215+
/**
4216+
* Return a list of page types
4217+
* @param string $pagetype current page type
4218+
* @param stdClass $parentcontext Block's parent context
4219+
* @param stdClass $currentcontext Current context of block
4220+
*/
4221+
function course_pagetypelist($pagetype, $parentcontext, $currentcontext) {
4222+
// if above course context ,display all course fomats
4223+
list($currentcontext, $course, $cm) = get_context_info_array($currentcontext->id);
4224+
if ($course->id == SITEID) {
4225+
return array('*'=>get_string('page-x', 'pagetype'));
4226+
} else {
4227+
return array('*'=>get_string('page-x', 'pagetype'),
4228+
'course-*'=>get_string('page-course-x', 'pagetype'),
4229+
'course-view-*'=>get_string('page-course-view-x', 'pagetype'),
4230+
'mod-*'=>get_string('page-mod-x', 'pagetype')
4231+
);
4232+
}
4233+
}

lang/en/block.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@
3030
$string['bracketfirst'] = '{$a} (first)';
3131
$string['bracketlast'] = '{$a} (last)';
3232
$string['contexts'] = 'Page contexts';
33+
$string['contexts_help'] = 'Contexts are more specific types of pages where this block can be displayed within the original block location. You will have different options here depending on the original block location and your current location. For example, you can restrict a block to only appearing on forum pages in a course by adding the block to the course (making it appear on all sub-pages), then going into a forum and editing the block settings again to restrict display to just forum pages.';
34+
$string['createdat'] = 'Original block location';
35+
$string['createdat_help'] = 'This is the original location where the block was created, even though other block settings may cause it to appear in other locations (contexts) within this original location. For example, a block created in a course could be displayed on one or more pages within that course only. A block created on the front page, however, could be displayed throughout the site.';
3336
$string['defaultregion'] = 'Default region';
37+
$string['defaultregion_help'] = 'Themes may define one or more named block regions where blocks are displayed. This setting defines which of these you want this block to appear in by default. The region may be overridden on specific pages if required.';
3438
$string['defaultweight'] = 'Default weight';
39+
$string['defaultweight_help'] = 'The default weight allows you to choose roughly where you want the block to appear in the chosen region, either at the top or the bottom. The final location is calculated from all the blocks in that region (for example, only one block can actually be at the top). This value can be overridden on specific pages if required.';
3540
$string['moveblockhere'] = 'Move block here';
3641
$string['movingthisblockcancel'] = 'Moving this block ({$a})';
3742
$string['onthispage'] = 'On this page';
@@ -43,9 +48,9 @@
4348
$string['showonfrontpageandsubs'] = 'Display on the front page and any pages added to the front page';
4449
$string['showonfrontpageonly'] = 'Display on the front page only';
4550
$string['site-*'] = 'Any top-level site page';
46-
$string['subpages'] = 'Specific sub-page';
47-
$string['restrictpagetypes'] = 'Restrict to these page types';
48-
$string['thisspecificpage'] = 'This specific page (page {$a})';
51+
$string['subpages'] = 'Select pages';
52+
$string['restrictpagetypes'] = 'Display on page types';
53+
$string['thisspecificpage'] = 'This specific page';
4954
$string['undockall'] = 'Undock all';
5055
$string['undockitem'] = 'Undock this item';
5156
$string['visible'] = 'Visible';

lang/en/blog.php

+3
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,6 @@
176176
$string['viewuserentries'] = 'View all entries by {$a}';
177177
$string['worldblogs'] = 'The world can read entries set to be world-accessible';
178178
$string['wrongpostid'] = 'Wrong blog post id';
179+
$string['page-blog-edit'] = 'Blog editing pages';
180+
$string['page-blog-index'] = 'Blog listing pages';
181+
$string['page-blog-x'] = 'All blog pages';

lang/en/notes.php

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
$string['notesdisabled'] = 'Notes are disabled, sorry.';
4747
$string['notesnotvisible'] = 'You are not allowed to view the notes.';
4848
$string['nouser'] = 'You must select a user';
49+
$string['page-notes-x'] = 'Any note pages';
50+
$string['page-notes-index'] = 'Notes main page';
4951
$string['personal'] = 'personal';
5052
$string['personalnotes'] = 'Personal notes';
5153
$string['publishstate'] = 'Context';

lang/en/pagetype.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26-
$string['page-blog-index'] = 'Blog listing pages';
27-
$string['page-blog-x'] = 'All blog pages';
28-
$string['page-course-view-topics'] = 'Any course main page in topics format';
29-
$string['page-course-view-weeks'] = 'Any course main page in weeks format';
3026
$string['page-course-view-x'] = 'Any type of course main page';
3127
$string['page-course-x'] = 'Any course page';
3228
$string['page-mod-x'] = 'Any activity module page';
3329
$string['page-mod-x-view'] = 'Any main activity module page';
34-
$string['page-my-index'] = 'Users\' My home page';
30+
$string['page-my-index'] = 'My home page';
3531
$string['page-site-index'] = 'The front page only';
3632
$string['page-site-x'] = 'Any top-level site page';
37-
$string['page-tag-x'] = 'All tag pages';
3833
$string['page-user-view'] = 'Only user profile pages';
34+
$string['page-user-profile'] = 'Only user profile pages';
3935
$string['page-user-x'] = 'All user pages';
4036
$string['page-x'] = 'Any page';

lang/en/question.php

+5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@
186186
$string['notenoughdatatomovequestions'] = 'You need to provide the question ids of questions you want to move.';
187187
$string['notflagged'] = 'Not flagged';
188188
$string['novirtualquestiontype'] = 'No virtual question type for question type {$a}';
189+
$string['page-question-x'] = 'Any question page';
190+
$string['page-question-edit'] = 'Question editing page';
191+
$string['page-question-category'] = 'Question category page';
192+
$string['page-question-import'] = 'Question import page';
193+
$string['page-question-export'] = 'Question export page';
189194
$string['parentcategory'] = 'Parent category';
190195
$string['parentcategory_help'] = 'The parent category is the one in which the new category will be placed. "Top" means that this category is not contained in any other category. Category contexts are shown in bold type. There must be at least one category in each context.';
191196
$string['parentcategory_link'] = 'question/category';

lang/en/tag.php

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
$string['addedotag'] = '"{$a}" was added as an official tag.';
2727
$string['addotags'] = 'Add official tags';
2828
$string['addtagtomyinterests'] = 'Add "{$a}" to my interests';
29+
$string['alltagpages'] = 'All tag pages';
2930
$string['count'] = 'Count';
3031
$string['delete'] = 'Delete';
3132
$string['deleted'] = 'Deleted';
@@ -82,3 +83,7 @@
8283
$string['updated'] = 'Updated';
8384
$string['updatetag'] = 'Update';
8485
$string['withselectedtags'] = 'With selected tags...';
86+
$string['page-tag-x'] = 'All tag pages';
87+
$string['page-tag-index'] = 'Single tag page';
88+
$string['page-tag-search'] = 'Tag search page';
89+
$string['page-tag-manage'] = 'Tag manage page';

0 commit comments

Comments
 (0)