mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
(mvc, fieldtype) wrong event for setting initial data in UniqueIdField
This commit is contained in:
parent
e5cbe0cfdf
commit
088ca26680
@ -51,23 +51,20 @@ class UniqueIdField extends BaseField
|
||||
*/
|
||||
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
|
||||
* @return array
|
||||
*/
|
||||
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();
|
||||
// unique id may not change..
|
||||
$validators[] = new InclusionIn(array('message' => $this->internalValidationMessage,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user