Skip to content
Permalink
Browse files

Removed `$useIndex` support of false

  • Loading branch information...
lilHermit committed Feb 6, 2017
1 parent f316b1f commit 8b05ce843553db02879c3c9886d4111211af8403
Showing with 14 additions and 22 deletions.
  1. +4 −16 src/View/StringTemplate.php
  2. +10 −6 tests/TestCase/View/StringTemplateTest.php
@@ -328,15 +328,9 @@ protected function _formatAttribute($key, $value, $escape = true)
/**
* Adds a class and returns a unique list either in array or space separated
*
* ### Options
*
* - `useIndex` if you are inputting an array with an 'element' other than 'class'.
* Also setting to 'false' will manipulate the whole array (default is 'class')
*
* @param array|string $input The array or string to add the class to
* @param array|string $newClass the new class or classes to add
* @param string $useIndex if you are inputting an array with an 'element' other than 'class'.
* Also setting to 'false' will manipulate the whole array (default is 'class')
* @param string $useIndex if you are inputting an array with an element other than default of 'class'.
* @return array|string
*/
public function addClass($input, $newClass, $useIndex = 'class')
@@ -346,10 +340,11 @@ public function addClass($input, $newClass, $useIndex = 'class')
return $input;
}
if (is_string($useIndex) && is_array($input)) {
if (is_array($input)) {
$class = Hash::get($input, $useIndex, []);
} else {
$class = $input;
$input = [];
}
// Convert and sanitise the inputs
@@ -367,14 +362,7 @@ public function addClass($input, $newClass, $useIndex = 'class')
$class = array_unique(array_merge($class, $newClass));
if (is_string($useIndex)) {
if (!is_array($input)) {
$input = [];
}
$input = Hash::insert($input, $useIndex, $class);
} else {
$input = $class;
}
$input = Hash::insert($input, $useIndex, $class);
return $input;
}
@@ -397,16 +397,20 @@ public function testAddClassMethodUseIndex()
$result = $this->template->addClass(
[
'current_class',
'text'
'class' => [
'current_class',
'text'
]
],
'new_class',
false
'non-existent'
);
$this->assertEquals($result, [
'current_class',
'text',
'new_class'
'class' => [
'current_class',
'text'
],
'non-existent' => ['new_class']
]);
}
}

0 comments on commit 8b05ce8

Please sign in to comment.
You can’t perform that action at this time.