Skip to content

Commit

Permalink
declare instance variable, add docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Hartmann committed Jul 17, 2016
1 parent 48bd343 commit b37f531
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -205,6 +205,13 @@ class FormHelper extends Helper
*/
protected $_lastAction = '';

/**
* The values sources to be used to retrieve prefilled input values from.
*
* @var array
*/
protected $_valuesSources = [];

/**
* Construct the widgets and binds the default context providers
*
Expand Down Expand Up @@ -359,7 +366,7 @@ public function create($model = null, array $options = [])
'encoding' => strtolower(Configure::read('App.encoding')),
'templates' => null,
'idPrefix' => null,
'valuesSources' => [],
'valuesSources' => 'context',
];

if (isset($options['action'])) {
Expand Down Expand Up @@ -2676,18 +2683,40 @@ public function implementedEvents()
return [];
}

/**
* Gets the value sources.
*
* Returns a list, but at least one item, of valid sources, such as: `'context'`, `'data'` and `'query'`.
*
* @return array List of value sources.
*/
public function getValuesSources()
{
return $this->_valuesSources;
}

/**
* Sets the value sources.
*
* Valid values are `'context'`, `'data'` and `'query'`.
* You need to supply one valid context or multiple, as a list of strings. Order sets priority.
*
* @param string|array $sources A string or a list of strings identifying a source.
* @return $this
*/
public function setValuesSources($sources)
{
$this->_valuesSources = array_values(array_intersect((array)$sources, ['context', 'data', 'query']));

return $this;
}

/**
* Gets a single field value from the sources available.
*
* @param string $fieldname The fieldname to fetch the value for.
* @return string Field value derived from sources.
*/
public function getSourceValue($fieldname)
{
foreach ($this->getValuesSources() as $valuesSource) {
Expand Down

0 comments on commit b37f531

Please sign in to comment.