Permalink
Browse files

Merge branch 'wip-MDL-39824-m25' of http://github.com/samhemelryk/moodle

 into MOODLE_25_STABLE
  • Loading branch information...
danpoltawski committed Jun 10, 2013
2 parents f981643 + 7174920 commit 6f4232974ed56fec5b6ecb7e7140c4c598d6d133
View
@@ -341,7 +341,7 @@ protected function get_move_target_url($region, $weight) {
* output the blocks anyway, so we are not doing wasted effort.)
*
* @param string $region a block region that exists on this page.
- * @param object $output a core_renderer. normally the global $OUTPUT.
+ * @param core_renderer $output a core_renderer. normally the global $OUTPUT.
* @return boolean Whether there is anything in this region.
*/
public function region_has_content($region, $output) {
View
@@ -325,6 +325,14 @@ class theme_config {
*/
public $yuicssmodules = array('cssreset', 'cssfonts', 'cssgrids', 'cssbase');
+ /**
+ * An associative array of block manipulations that should be made if the user is using an rtl language.
+ * The key is the original block region, and the value is the block region to change to.
+ * This is used when displaying blocks for regions only.
+ * @var array
+ */
+ public $blockrtlmanipulations = array();
+
/**
* @var renderer_factory Instance of the renderer_factory implementation
* we are using. Implementation detail.
@@ -418,7 +426,7 @@ private function __construct($config) {
$configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer',
'parents_exclude_javascripts', 'layouts', 'enable_dock', 'enablecourseajax', 'supportscssoptimisation',
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector', 'doctype',
- 'yuicssmodules');
+ 'yuicssmodules', 'blockrtlmanipulations');
foreach ($config as $key=>$value) {
if (in_array($key, $configurable)) {
View
@@ -921,7 +921,7 @@ public function course_content_header($onlyifnotcalledbefore = false) {
$functioncalled = true;
$courseformat = course_get_format($this->page->course);
if (($obj = $courseformat->course_content_header()) !== null) {
- return $courseformat->get_renderer($this->page)->render($obj);
+ return html_writer::div($courseformat->get_renderer($this->page)->render($obj), 'course-content-header');
}
return '';
}
@@ -948,7 +948,7 @@ public function course_content_footer($onlyifnotcalledbefore = false) {
require_once($CFG->dirroot.'/course/lib.php');
$courseformat = course_get_format($this->page->course);
if (($obj = $courseformat->course_content_footer()) !== null) {
- return $courseformat->get_renderer($this->page)->render($obj);
+ return html_writer::div($courseformat->get_renderer($this->page)->render($obj), 'course-content-footer');
}
return '';
}
@@ -1228,6 +1228,7 @@ public function list_block_contents($icons, $items) {
* @return string the HTML to be output.
*/
public function blocks_for_region($region) {
+ $region = $this->page->apply_theme_region_manipulations($region);
$blockcontents = $this->page->blocks->get_content_for_region($region, $this);
$blocks = $this->page->blocks->get_blocks_for_region($region);
$lastblock = null;
@@ -2675,10 +2676,13 @@ public function tree_block_contents($items, $attrs = array()) {
*/
public function navbar() {
$items = $this->page->navbar->get_items();
+ $itemcount = count($items);
+ if ($itemcount === 0) {
+ return '';
+ }
$htmlblocks = array();
// Iterate the navarray and display each node
- $itemcount = count($items);
$separator = get_separator();
for ($i=0;$i < $itemcount;$i++) {
$item = $items[$i];
@@ -2827,7 +2831,7 @@ protected function render_custom_menu(custom_menu $menu) {
$jscode = "(function(){{$jscode}})";
$this->page->requires->yui_module('node-menunav', $jscode);
// Build the root nodes as required by YUI
- $content = html_writer::start_tag('div', array('id'=>'custom_menu_'.$menucount, 'class'=>'yui3-menu yui3-menu-horizontal javascript-disabled'));
+ $content = html_writer::start_tag('div', array('id'=>'custom_menu_'.$menucount, 'class'=>'yui3-menu yui3-menu-horizontal javascript-disabled custom-menu'));
$content .= html_writer::start_tag('div', array('class'=>'yui3-menu-content'));
$content .= html_writer::start_tag('ul');
// Render each child
@@ -3028,6 +3032,146 @@ protected function render_tabobject(tabobject $tabobject) {
return $str;
}
+
+ /**
+ * Get the HTML for blocks in the given region.
+ *
+ * @since 2.5.1 2.6
+ * @param string $region The region to get HTML for.
+ * @return string HTML.
+ */
+ public function blocks($region, $classes = array(), $tag = 'aside') {
+ $displayregion = $this->page->apply_theme_region_manipulations($region);
+ $classes = (array)$classes;
+ $classes[] = 'block-region';
+ $attributes = array(
+ 'id' => 'block-region-'.preg_replace('#[^a-zA-Z0-9_\-]+#', '-', $displayregion),
+ 'class' => join(' ', $classes),
+ 'data-blockregion' => $displayregion,
+ 'data-droptarget' => '1'
+ );
+ return html_writer::tag($tag, $this->blocks_for_region($region), $attributes);
+ }
+
+ /**
+ * Returns the CSS classes to apply to the body tag.
+ *
+ * @since 2.5.1 2.6
+ * @param array $additionalclasses Any additional classes to apply.
+ * @return string
+ */
+ public function body_css_classes(array $additionalclasses = array()) {
+ // Add a class for each block region on the page.
+ // We use the block manager here because the theme object makes get_string calls.
+ foreach ($this->page->blocks->get_regions() as $region) {
+ $additionalclasses[] = 'has-region-'.$region;
+ if ($this->page->blocks->region_has_content($region, $this)) {
+ $additionalclasses[] = 'used-region-'.$region;
+ } else {
+ $additionalclasses[] = 'empty-region-'.$region;
+ }
+ }
+ foreach ($this->page->layout_options as $option => $value) {
+ if ($value) {
+ $additionalclasses[] = 'layout-option-'.$option;
+ }
+ }
+ $css = $this->page->bodyclasses .' '. join(' ', $additionalclasses);
+ return $css;
+ }
+
+ /**
+ * The ID attribute to apply to the body tag.
+ *
+ * @since 2.5.1 2.6
+ * @return string
+ */
+ public function body_id() {
+ return $this->page->bodyid;
+ }
+
+ /**
+ * Returns HTML attributes to use within the body tag. This includes an ID and classes.
+ *
+ * @since 2.5.1 2.6
+ * @param string|array $additionalclasses Any additional classes to give the body tag,
+ * @return string
+ */
+ public function body_attributes($additionalclasses = array()) {
+ if (!is_array($additionalclasses)) {
+ $additionalclasses = explode(' ', $additionalclasses);
+ }
+ return ' id="'. $this->body_id().'" class="'.$this->body_css_classes($additionalclasses).'"';
+ }
+
+ /**
+ * Gets HTML for the page heading.
+ *
+ * @since 2.5.1 2.6
+ * @param string $tag The tag to encase the heading in. h1 by default.
+ * @return string HTML.
+ */
+ public function page_heading($tag = 'h1') {
+ return html_writer::tag($tag, $this->page->heading);
+ }
+
+ /**
+ * Gets the HTML for the page heading button.
+ *
+ * @since 2.5.1 2.6
+ * @return string HTML.
+ */
+ public function page_heading_button() {
+ return $this->page->button;
+ }
+
+ /**
+ * Returns the Moodle docs link to use for this page.
+ *
+ * @since 2.5.1 2.6
+ * @param string $text
+ * @return string
+ */
+ public function page_doc_link($text = null) {
+ if ($text === null) {
+ $text = get_string('moodledocslink');
+ }
+ $path = page_get_doc_link_path($this->page);
+ if (!$path) {
+ return '';
+ }
+ return $this->doc_link($path, $text);
+ }
+
+ /**
+ * Returns the page heading menu.
+ *
+ * @since 2.5.1 2.6
+ * @return string HTML.
+ */
+ public function page_heading_menu() {
+ return $this->page->headingmenu;
+ }
+
+ /**
+ * Returns the title to use on the page.
+ *
+ * @since 2.5.1 2.6
+ * @return string
+ */
+ public function page_title() {
+ return $this->page->title;
+ }
+
+ /**
+ * Returns the URL for the favicon.
+ *
+ * @since 2.5.1 2.6
+ * @return string The favicon URL
+ */
+ public function favicon() {
+ return $this->pix_url('favicon', 'theme');
+ }
}
/**
View
@@ -51,7 +51,8 @@
* the forum or quiz table) that this page belongs to. Will be null
* if this page is not within a module.
* @property-read array $alternativeversions Mime type => object with ->url and ->title.
- * @property-read blocks_manager $blocks The blocks manager object for this page.
+ * @property-read block_manager $blocks The blocks manager object for this page.
+ * @property-read array $blockmanipulations
* @property-read string $bodyclasses A string to use within the class attribute on the body tag.
* @property-read string $bodyid A string to use as the id of the body tag.
* @property-read string $button The HTML to go where the Turn editing on button normally goes.
@@ -637,6 +638,22 @@ protected function magic_get_theme() {
return $this->_theme;
}
+ /**
+ * Returns an array of minipulations or false if there are none to make.
+ *
+ * @since 2.5.1 2.6
+ * @return bool|array
+ */
+ protected function magic_get_blockmanipulations() {
+ if (!right_to_left()) {
+ return false;
+ }
+ if (is_null($this->_theme)) {
+ $this->initialise_theme_and_output();
+ }
+ return $this->_theme->blockrtlmanipulations;
+ }
+
/**
* Please do not call this method directly, use the ->devicetypeinuse syntax. {@link moodle_page::__get()}.
* @return string The device type being used.
@@ -1825,4 +1842,18 @@ public function get_popup_notification_allowed() {
public function set_popup_notification_allowed($allowed) {
$this->_popup_notification_allowed = $allowed;
}
+
+ /**
+ * Returns the block region having made any required theme manipulations.
+ *
+ * @since 2.5.1 2.6
+ * @param string $region
+ * @return string
+ */
+ public function apply_theme_region_manipulations($region) {
+ if ($this->blockmanipulations && isset($this->blockmanipulations[$region])) {
+ return $this->blockmanipulations[$region];
+ }
+ return $region;
+ }
}
View
@@ -909,20 +909,37 @@ function close_window($delay = 0, $reloadopener = false) {
* @return string The link to user documentation for this current page
*/
function page_doc_link($text='') {
- global $CFG, $PAGE, $OUTPUT;
+ global $OUTPUT, $PAGE;
+ $path = page_get_doc_link_path($PAGE);
+ if (!$path) {
+ return '';
+ }
+ return $OUTPUT->doc_link($path, $text);
+}
+
+/**
+ * Returns the path to use when constructing a link to the docs.
+ *
+ * @since 2.5.1 2.6
+ * @global stdClass $CFG
+ * @param moodle_page $page
+ * @return string
+ */
+function page_get_doc_link_path(moodle_page $page) {
+ global $CFG;
if (empty($CFG->docroot) || during_initial_install()) {
return '';
}
- if (!has_capability('moodle/site:doclinks', $PAGE->context)) {
+ if (!has_capability('moodle/site:doclinks', $page->context)) {
return '';
}
- $path = $PAGE->docspath;
+ $path = $page->docspath;
if (!$path) {
return '';
}
- return $OUTPUT->doc_link($path, $text);
+ return $path;
}
Oops, something went wrong.

0 comments on commit 6f42329

Please sign in to comment.