helpers/icon: support webfont shortcuts

* set icon class instead of icon image if no such is given
* fix TODO: merge parameter classes

refs #6936
This commit is contained in:
Thomas Gelf 2014-11-13 15:17:36 +01:00
parent 86a9c7f8c6
commit 1aa8858dca

View File

@ -51,19 +51,32 @@ $this->addHelperFunction('img', function ($url, array $properties = array()) use
}); });
$this->addHelperFunction('icon', function ($img, $title = null, array $properties = array()) use ($view) { $this->addHelperFunction('icon', function ($img, $title = null, array $properties = array()) use ($view) {
// TODO: join with classes passed in $properties? $isClass = strpos($img, '.') === false;
$attributes = array( $class = null;
'class' => 'icon',
); if ($isClass) {
$class = 'icon-' . $img;
} else {
$class = 'icon';
}
if ($title !== null) { if ($title !== null) {
$attributes['alt'] = $title; $properties['alt'] = $title;
$attributes['title'] = $title; $properties['title'] = $title;
} }
return $view->img( if ($class !== null) {
'img/icons/' . $img, if (isset($props['class'])) {
array_merge($attributes, $properties) $properties['class'] .= ' ' . $class;
); } else {
$properties['class'] = $class;
}
}
if ($isClass) {
return sprintf('<i %s ></i>', $view->propertiesToString($properties));
} else {
return $view->img('img/icons/' . $img, $properties);
}
}); });
$this->addHelperFunction('propertiesToString', function ($properties) use ($view) { $this->addHelperFunction('propertiesToString', function ($properties) use ($view) {