From 7b218e86ab5f0efda607e620450d394c609804fc Mon Sep 17 00:00:00 2001 From: apsdehal Date: Wed, 22 Jan 2014 17:59:24 +0530 Subject: [PATCH] MDL-39337 html_writer: Added img() function img function has been added to the html_writer. use it by calling the function as shown: html_writer::img('foo.com','Foo',array('title'=>'Foo2')); This will result in the following string: Foo --- lib/outputcomponents.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 5157293a23b..0a04e79c8f2 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1101,6 +1101,22 @@ class html_writer { return $output; } + /** + * Generates a simple image tag with attributes. + * + * @param string $src The source of image + * @param string $alt The alternate text for image + * @param array $attributes The tag attributes (array('height' => $max_height, 'class' => 'class1') etc.) + * @return string HTML fragment + */ + public static function img($src, $alt, array $attributes = null) { + $attributes = (array)$attributes; + $attributes['src'] = $src; + $attributes['alt'] = $alt; + + return self::empty_tag('img', $attributes); + } + /** * Generates random html element id. *