public function testIcon() { $result = $this->Html->icon('foo'); $expected = ['i' => ['class' => 'glyphicon glyphicon-foo'], '/i']; $this->assertHtml($expected, $result); $result = $this->Html->icon('foo', ['iconSet' => 'fa']); $expected = ['i' => ['class' => 'fa fa-foo'], '/i']; $this->assertHtml($expected, $result); $result = $this->Html->icon('foo', ['tag' => 'span']); $expected = ['span' => ['class' => 'glyphicon glyphicon-foo'], '/span']; $this->assertHtml($expected, $result); }
public function icon($name, array $options = []) { //TODO: make icon agnostic and as helper config option if (!isset($options['iconSet'])) { $options['iconSet'] = 'fa'; } return parent::icon($name, $options); }
/** * Creates an icon. * * This method surcharges the icon() method from BootstrapUI : * - fixed width by default * - fontAwesome by default * * Options : * - fixed: bool, If true, an fa-fw class will be applied (default) * - iconSet: string, icon prefix (usually 'glyphicon' or 'fa') * - class: Additionnal classes for the icon. * * @param string $name Icon name or space separated names (ie: 'home' or 'home 3x') * @param array $options An array of options * * @return string */ public function icon($name, array $options = []) { $options += ['iconSet' => 'fa', 'fixed' => true, 'class' => null]; $names = explode(' ', $name); foreach ($names as $string) { $options = $this->injectClasses($options['iconSet'] . '-' . $string, $options); } if ($options['fixed']) { $options = $this->injectClasses($options['iconSet'] . '-fw', $options); } unset($options['fixed']); return parent::icon($name, $options); }