Skip to content

Commit

Permalink
Add docs and simplify code for initInputField.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 14, 2014
1 parent 09c3dea commit 2f314d9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/View/Helper/FormHelper.php
Expand Up @@ -2833,20 +2833,25 @@ protected function _generateOptions($name, $options = array()) {
* - `secure` - boolean whether or not the field should be added to the security fields.
* Disabling the field using the `disabled` option, will also omit the field from being
* part of the hashed key.
* - `default` - mixed - The value to use if there is no value in the form's context.
* - `disabled` - mixed - Either a boolean indicating disabled state, or the string in
* a numerically indexed value.
*
* This method will convert a numerically indexed 'disabled' into a associative
* value. FormHelper's internals expect associative options.
* This method will convert a numerically indexed 'disabled' into an associative
* array value. FormHelper's internals expect associative options.
*
* The output of this function is a more complete set of input attributes that
* can be passed to a form widget to generate the actual input.
*
* @param string $field Name of the field to initialize options for.
* @param array $options Array of options to append options into.
* @return array Array of options for the input.
*/
protected function _initInputField($field, $options = []) {
$secure = !empty($this->request['_Token']);
if (isset($options['secure'])) {
$secure = $options['secure'];
unset($options['secure']);
} else {
$secure = (isset($this->request['_Token']) && !empty($this->request['_Token']));
}
$context = $this->_getContext();

Expand All @@ -2864,15 +2869,14 @@ protected function _initInputField($field, $options = []) {

if (isset($options['value']) && !isset($options['val'])) {
$options['val'] = $options['value'];
unset($options['value']);
}
if (!isset($options['val'])) {
$options['val'] = $context->val($field);
}
if (!isset($options['val']) && isset($options['default'])) {
$options['val'] = $options['default'];
}
unset($options['default']);
unset($options['value'], $options['default']);

$options += (array)$context->attributes($field);

Expand Down

0 comments on commit 2f314d9

Please sign in to comment.