From 5e32ecea113bb3906c5bc30eef1e254049271c71 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 31 May 2018 00:49:41 +0530 Subject: [PATCH] Add methods to get/set modelless form data. --- src/Form/Form.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Form/Form.php b/src/Form/Form.php index 5c2197b346f..a8e3713c50f 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -20,6 +20,7 @@ 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; @@ -304,6 +305,26 @@ protected function _execute(array $data) return true; } + public function getData($field = null) + { + if ($field === null) { + return $this->_data; + } + + return Hash::get($this->_data, $field); + } + + public function setData(array $data, $merge = true) + { + if ($merge) { + $this->_data = Hash::merge($this->_data, $data); + } else { + $this->_data = $data; + } + + return $this; + } + /** * Get the printable version of a Form instance. *