Support booleans in SilverStripe\View\Parsers\Diff::getHTMLChunks

Convert booleans to strings ("true", "false") so they can be diff'd for display.
This commit is contained in:
Mike Cochrane 2017-04-07 13:21:49 +12:00 committed by Mike Cochrane
parent b8c3bf6fa5
commit 9d77537061

View File

@ -161,15 +161,20 @@ class Diff extends \Diff
}
/**
* @param string|array $content If passed as an array, values will be concatenated with a comma.
* @param string|bool|array $content If passed as an array, values will be concatenated with a comma.
* @return array
*/
public static function getHTMLChunks($content)
{
if ($content && !is_string($content) && !is_array($content) && !is_numeric($content)) {
if ($content && !is_string($content) && !is_array($content) && !is_numeric($content) && !is_bool($content)) {
throw new InvalidArgumentException('$content parameter needs to be a string or array');
}
if (is_bool($content)) {
// Convert boolean to strings
$content = $content ? "true" : "false";
}
if (is_array($content)) {
// Convert array to CSV
$content = implode(',', $content);
}