diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 74f0d370894..814f8ddabf9 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1733,6 +1733,97 @@ class html_writer { return $label; } + + /** + * Combines a class parameter with other attributes. Aids in code reduction + * because the class parameter is very frequently used. + * + * If the class attribute is specified both in the attributes and in the + * class parameter, the two values are combined with a space between. + * + * @param string $class Optional CSS class (or classes as space-separated list) + * @param array $attributes Optional other attributes as array + * @return array Attributes (or null if still none) + */ + private static function add_class($class = '', array $attributes = null) { + if ($class !== '') { + $classattribute = array('class' => $class); + if ($attributes) { + if (array_key_exists('class', $attributes)) { + $attributes['class'] = trim($attributes['class'] . ' ' . $class); + } else { + $attributes = $classattribute + $attributes; + } + } else { + $attributes = $classattribute; + } + } + return $attributes; + } + + /** + * Creates a