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) {
// TODO: join with classes passed in $properties?
$attributes = array(
'class' => 'icon',
);
$isClass = strpos($img, '.') === false;
$class = null;
if ($isClass) {
$class = 'icon-' . $img;
} else {
$class = 'icon';
}
if ($title !== null) {
$attributes['alt'] = $title;
$attributes['title'] = $title;
$properties['alt'] = $title;
$properties['title'] = $title;
}
return $view->img(
'img/icons/' . $img,
array_merge($attributes, $properties)
);
if ($class !== null) {
if (isset($props['class'])) {
$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) {