mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-39838 renderer: new methods for body classes and id
This commit is contained in:
parent
8cf2b9ab9b
commit
3707972a78
1 changed files with 51 additions and 0 deletions
|
@ -3048,6 +3048,57 @@ EOD;
|
||||||
);
|
);
|
||||||
return html_writer::tag($tag, $this->blocks_for_region($region), $attributes);
|
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).'"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue