Commit ded69cf6 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(mvc) add ChangeCase to base field type, enforces case on change event

(cherry picked from commit c3358d74)
parent ab143f7e
......@@ -102,6 +102,11 @@ abstract class BaseField
*/
protected $internalAttributes = array();
/**
* @var string $internalToLower
*/
private $internalChangeCase = null;
/**
* generate a new UUID v4 number
* @return string uuid v4 number
......@@ -274,6 +279,11 @@ abstract class BaseField
$this->internalInitialValue = $value;
}
$this->internalValue = $value;
// apply filters, may be extended later.
$filters = array('applyFilterChangeCase');
foreach ($filters as $filter) {
$this->$filter();
}
}
/**
......@@ -539,6 +549,35 @@ abstract class BaseField
}
}
/**
* change character case on save
* @param string $value set case type, upper, lower, null (don't change)
*/
public function setChangeCase($value)
{
if (strtoupper(trim($value)) == 'UPPER') {
$this->internalChangeCase = 'UPPER';
} elseif (strtoupper(trim($value)) == 'LOWER') {
$this->internalChangeCase = 'LOWER';
} else {
$this->internalChangeCase = null;
}
}
/**
* apply change case to this node, called by setValue
*/
private function applyFilterChangeCase()
{
if (!empty($this->internalValue)) {
if ($this->internalChangeCase == 'UPPER') {
$this->internalValue = strtoupper($this->internalValue);
} elseif ($this->internalChangeCase == 'LOWER') {
$this->internalValue = strtolower($this->internalValue);
}
}
}
/**
* return object type as string
* @return string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment