Exemple #1
0
 /**
  * Returns whether the field can be left blank according to `allowEmpty`
  *
  * @param ValidationSet $field the set of rules for a field
  * @param array $context a key value list of data containing the validation context.
  * @return bool
  */
 protected function _canBeEmpty($field, $context)
 {
     $allowed = $field->isEmptyAllowed();
     if (!is_string($allowed) && is_callable($allowed)) {
         return $allowed($context);
     }
     $newRecord = $context['newRecord'];
     if (in_array($allowed, array('create', 'update'), true)) {
         $allowed = $allowed === 'create' && $newRecord || $allowed === 'update' && !$newRecord;
     }
     return $allowed;
 }
 /**
  * Returns whether the field can be left blank according to `allowEmpty`
  *
  * @param ValidationSet $field the set of rules for a field
  * @param bool $newRecord whether the data to be validated is new or to be updated.
  * @return bool
  */
 protected function _canBeEmpty($field, $newRecord)
 {
     $allowed = $field->isEmptyAllowed();
     if (in_array($allowed, array('create', 'update'), true)) {
         $allowed = $allowed === 'create' && $newRecord || $allowed === 'update' && !$newRecord;
     }
     return $allowed;
 }