Feature #3595
Convert integer types to boolean for if viewhelper
Status: | Closed | Start date: | 2009-06-06 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Bastian Waidelich | % Done: | 0% |
|
Category: | ViewHelpers | |||
Target version: | 1.0.0 alpha 2 | |||
Has patch: |
Description
Hello, after wndeirng why certain if conditions didn't work in my flow templates, i figures out it was because it didn't convert interger values to boolean correctely. I suggest modifiying the convertArgumentValue method in the Tx_Fluid_Core_SyntaxTree_ViewHelperNode accordingly. Positive integer values superior to 0 are considered true all others are false.
/**
* Convert argument strings to their equivalents. Needed to handle strings with a boolean meaning.
*
* @param mixed $value Value to be converted
* @param string $type Target type
* @return mixed New value
* @author Sebastian Kurfürst <sebastian@typo3.org>
* @author Bastian Waidelich <bastian@typo3.org>
* @todo re-check boolean conditions
*/
protected function convertArgumentValue($value, $type) {
//echo "<br>$value - $type";
if ($type === 'boolean') {
if (is_string($value)) {
//echo "string";
return (strtolower($value) !== 'false' && !empty($value));
}
if (is_array($value) || (is_object($value) && $value instanceof Countable)) {
//echo "array";
return count($value) > 0;
}
if (is_object($value)) {
//echo "object";
return TRUE;
}
//----> NEW CODE
if (is_integer($value)) {
//echo "integer";
return $value > 0;
}
// END NEW CODE ---->
return FALSE;
}
return $value;
}
Related issues
History
#1 Updated by Bastian Waidelich about 6 years ago
- Status changed from New to Closed
- Assigned To set to Bastian Waidelich
This was fixed in r2345.
See http://forge.typo3.org/issues/show/3412
#2 Updated by Robert Lemke about 6 years ago
- Target version set to 1.0.0 alpha 2