diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-07-15 17:40:18 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-07-15 17:40:18 +0000 |
commit | 5a8452c55b9e6d7fcef921a7b56c23ef29eec3a9 (patch) | |
tree | 7285272f52d423a3a49b2a8ac3a596fb5939c49d /includes | |
parent | b692036962b8d2c5c2b12749cf662d537a889375 (diff) | |
download | brdo-5a8452c55b9e6d7fcef921a7b56c23ef29eec3a9.tar.gz brdo-5a8452c55b9e6d7fcef921a7b56c23ef29eec3a9.tar.bz2 |
- Patch #493746 by JohnAlbin, ultimateboy, moshe weitzman: Enhance drupal_attributes() for multiple valued values.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 18 | ||||
-rw-r--r-- | includes/theme.inc | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/includes/common.inc b/includes/common.inc index 7e553e473..487a716e9 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2122,19 +2122,23 @@ function url($path = NULL, array $options = array()) { /** * Format an attribute string to insert in a tag. * + * Each array key and its value will be formatted into an HTML attribute string. + * If a value is itself an array, then each array element is concatenated with a + * space between each value (e.g. a multi-value class attribute). + * * @param $attributes * An associative array of HTML attributes. * @return * An HTML string ready for insertion in a tag. */ function drupal_attributes($attributes = array()) { - if (is_array($attributes)) { - $t = ''; - foreach ($attributes as $key => $value) { - $t .= " $key=" . '"' . check_plain($value) . '"'; + foreach ($attributes as $attribute => $data) { + if (is_array($data)) { + $data = implode(' ', $data); } - return $t; + $items[] = $attribute . '="' . check_plain($data) . '"'; } + return isset($items) ? ' ' . implode(' ', $items) : ''; } /** @@ -4100,7 +4104,7 @@ function drupal_common_theme() { 'arguments' => array('links' => NULL, 'attributes' => array('class' => 'links')), ), 'image' => array( - 'arguments' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), + 'arguments' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => array(), 'getsize' => TRUE), ), 'breadcrumb' => array( 'arguments' => array('breadcrumb' => NULL), @@ -4124,7 +4128,7 @@ function drupal_common_theme() { 'arguments' => array('type' => MARK_NEW), ), 'item_list' => array( - 'arguments' => array('items' => array(), 'title' => NULL, 'type' => 'ul', 'attributes' => NULL), + 'arguments' => array('items' => array(), 'title' => NULL, 'type' => 'ul', 'attributes' => array()), ), 'more_help_link' => array( 'arguments' => array('url' => NULL), diff --git a/includes/theme.inc b/includes/theme.inc index aee5e320f..f8ba34f55 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1335,7 +1335,7 @@ function theme_links($links, $attributes = array('class' => 'links')) { * @return * A string containing the image tag. */ -function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { +function theme_image($path, $alt = '', $title = '', $attributes = array(), $getsize = TRUE) { if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) { $attributes = drupal_attributes($attributes); $url = (url($path) == $path) ? $path : (base_path() . $path); |