Skip to content

Commit

Permalink
Add methods to get/set modelless form data.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 1, 2018
1 parent fb88916 commit 5e32ece
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Form/Form.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 5e32ece

Please sign in to comment.