|
|
@@ -1036,12 +1036,74 @@ trait EntityTrait
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Get a list of invalid fields and their data for errors upon validation/patching
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getInvalid()
|
|
|
+ {
|
|
|
+ return $this->_invalid;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get a single value of an invalid field. Returns null if not set.
|
|
|
+ *
|
|
|
+ * @param string $field The name of the field.
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getInvalidField($field)
|
|
|
+ {
|
|
|
+ $value = isset($this->_invalid[$field]) ? $this->_invalid[$field] : null;
|
|
|
+
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set fields as invalid and not patchable into the entity.
|
|
|
+ *
|
|
|
+ * This is useful for batch operations when one needs to get the original value for an error message after patching.
|
|
|
+ * This value could not be patched into the entity and is simply copied into the _invalid property for debugging purposes
|
|
|
+ * or to be able to log it away.
|
|
|
+ *
|
|
|
+ * @param array $fields The values to set.
|
|
|
+ * @param bool $overwrite Whether or not to overwrite pre-existing values for $field.
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setInvalid(array $fields, $overwrite = false)
|
|
|
+ {
|
|
|
+ foreach ($fields as $field => $value) {
|
|
|
+ if ($overwrite === true) {
|
|
|
+ $this->_invalid[$field] = $value;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $this->_invalid += [$field => $value];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets a field as invalid and not patchable into the entity.
|
|
|
+ *
|
|
|
+ * @param string $field The value to set.
|
|
|
+ * @param mixed $value The invalid value to be set for $field.
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setInvalidField($field, $value)
|
|
|
+ {
|
|
|
+ $this->_invalid[$field] = $value;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Sets a field as invalid and not patchable into the entity.
|
|
|
*
|
|
|
* This is useful for batch operations when one needs to get the original value for an error message after patching.
|
|
|
* This value could not be patched into the entity and is simply copied into the _invalid property for debugging purposes
|
|
|
* or to be able to log it away.
|
|
|
*
|
|
|
+ * @deprecated 3.5 Use getInvalid()/getInvalidField()/setInvalid() instead.
|
|
|
* @param string|array|null $field The field to get invalid value for, or the value to set.
|
|
|
* @param mixed|null $value The invalid value to be set for $field.
|
|
|
* @param bool $overwrite Whether or not to overwrite pre-existing values for $field.
|