Commit 088ca266 authored by Ad Schellevis's avatar Ad Schellevis

(mvc, fieldtype) wrong event for setting initial data in UniqueIdField

parent e5cbe0cf
...@@ -51,23 +51,20 @@ class UniqueIdField extends BaseField ...@@ -51,23 +51,20 @@ class UniqueIdField extends BaseField
*/ */
private $initialValue = null; private $initialValue = null;
/**
* generate unique id (if none available) and store previous value for comparison before save
*/
public function eventPostLoading()
{
if (empty($this->internalValue)) {
$this->internalValue = uniqid('', true);
}
$this->initialValue = $this->internalValue;
}
/** /**
* retrieve field validators for this field type * retrieve field validators for this field type
* @return array * @return array
*/ */
public function getValidators() public function getValidators()
{ {
if (empty($this->internalValue) && empty($this->initialValue)) {
// trigger initial value on change, before returning validators
// (new nodes will always be marked as "changed", see isFieldChanged())
// Maybe we should add an extra event handler if this kind of scenarios happen more often, similar to
// actionPostLoadingEvent. (which is not triggered on setting data for a complete new structure node)
$this->internalValue = uniqid('', true);
$this->initialValue = $this->internalValue;
}
$validators = parent::getValidators(); $validators = parent::getValidators();
// unique id may not change.. // unique id may not change..
$validators[] = new InclusionIn(array('message' => $this->internalValidationMessage, $validators[] = new InclusionIn(array('message' => $this->internalValidationMessage,
......
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