|
|
@@ -20,6 +20,7 @@ use Cake\Event\EventDispatcherTrait;
|
|
|
use Cake\Event\EventListenerInterface;
|
|
|
use Cake\Event\EventManager;
|
|
|
use Cake\Form\Schema;
|
|
|
+use Cake\Utility\Hash;
|
|
|
use Cake\Validation\Validator;
|
|
|
use Cake\Validation\ValidatorAwareInterface;
|
|
|
use Cake\Validation\ValidatorAwareTrait;
|
|
|
@@ -90,6 +91,14 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
protected $_validator;
|
|
|
|
|
|
/**
|
|
|
+ * Form's data.
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ * @since 3.7.0
|
|
|
+ */
|
|
|
+ protected $_data = [];
|
|
|
+
|
|
|
+ /**
|
|
|
* Constructor
|
|
|
*
|
|
|
* @param \Cake\Event\EventManager|null $eventManager The event manager.
|
|
|
@@ -305,6 +314,37 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Get field data.
|
|
|
+ *
|
|
|
+ * @param string|null $field The field name or null to get data array with
|
|
|
+ * all fields.
|
|
|
+ * @return mixed
|
|
|
+ * @since 3.7.0
|
|
|
+ */
|
|
|
+ public function getData($field = null)
|
|
|
+ {
|
|
|
+ if ($field === null) {
|
|
|
+ return $this->_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Hash::get($this->_data, $field);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set form data.
|
|
|
+ *
|
|
|
+ * @param array $data Data array.
|
|
|
+ * @return $this
|
|
|
+ * @since 3.7.0
|
|
|
+ */
|
|
|
+ public function setData(array $data)
|
|
|
+ {
|
|
|
+ $this->_data = $data;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Get the printable version of a Form instance.
|
|
|
*
|
|
|
* @return array
|