Browse Source

Fix class attribute to be used properly.

mscherer 6 years ago
parent
commit
5cb19f3597

+ 4 - 0
src/View/Helper/FormatHelper.php

@@ -374,6 +374,10 @@ class FormatHelper extends Helper {
 				$attributes['title'] = __($attributes['title']);
 			}
 		}
+		if (isset($attributes['class'])) {
+			$options['class'] .= ' ' . $attributes['class'];
+			unset($attributes['class']);
+		}
 
 		$attributes += [
 			'data-placement' => 'bottom',

+ 9 - 0
tests/TestCase/View/Helper/FormatHelperTest.php

@@ -94,6 +94,15 @@ class FormatHelperTest extends TestCase {
 	/**
 	 * @return void
 	 */
+	public function testIconWithCustomClassAttributes() {
+		$result = $this->Format->icon('edit', [], ['class' => 'my-extra']);
+		$expected = '<i class="icon icon-edit fa fa-pencil my-extra" title="' . __d('tools', 'Edit') . '" data-placement="bottom" data-toggle="tooltip"></i>';
+		$this->assertEquals($expected, $result);
+	}
+
+	/**
+	 * @return void
+	 */
 	public function testIconWithCustomFontIcon() {
 		$this->Format->setConfig('fontIcons', ['edit' => 'fax fax-pen']);
 		$result = $this->Format->icon('edit');