Skip to content

Commit

Permalink
Updating FormHelper and its tests to use the request object.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 14, 2010
1 parent 0d3011d commit c5dfd12
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 108 deletions.
38 changes: 19 additions & 19 deletions cake/libs/view/helpers/form.php
Expand Up @@ -194,10 +194,10 @@ function create($model = null, $options = array()) {
$options = $model;
$model = null;
}
if (empty($model) && $model !== false && !empty($this->params['models'])) {
$model = $this->params['models'][0];
$this->defaultModel = $this->params['models'][0];
} elseif (empty($model) && empty($this->params['models'])) {
if (empty($model) && $model !== false && !empty($this->request['models'])) {
$model = $this->request['models'][0];
$this->defaultModel = $this->request['models'][0];
} elseif (empty($model) && empty($this->request['models'])) {
$model = false;
}

Expand All @@ -218,13 +218,13 @@ function create($model = null, $options = array()) {
if (isset($this->fieldset[$modelEntity]['key'])) {
$data = $this->fieldset[$modelEntity];
$recordExists = (
isset($this->data[$model]) &&
!empty($this->data[$model][$data['key']])
isset($this->request->data[$model]) &&
!empty($this->request->data[$model][$data['key']])
);

if ($recordExists) {
$created = true;
$id = $this->data[$model][$data['key']];
$id = $this->request->data[$model][$data['key']];
}
}

Expand All @@ -243,12 +243,12 @@ function create($model = null, $options = array()) {
if (empty($options['url']['controller'])) {
if (!empty($model) && $model != $this->defaultModel) {
$options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model));
} elseif (!empty($this->params['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->params['controller']);
} elseif (!empty($this->request['controller'])) {
$options['url']['controller'] = Inflector::underscore($this->request['controller']);
}
}
if (empty($options['action'])) {
$options['action'] = $this->params['action'];
$options['action'] = $this->request['action'];
}

$actionDefaults = array(
Expand Down Expand Up @@ -304,9 +304,9 @@ function create($model = null, $options = array()) {
unset($options['default']);
$htmlAttributes = array_merge($options, $htmlAttributes);

if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
if (isset($this->request['_Token']) && !empty($this->request['_Token'])) {
$append .= $this->hidden('_Token.key', array(
'value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand())
'value' => $this->request['_Token']['key'], 'id' => 'Token' . mt_rand())
);
}

Expand Down Expand Up @@ -341,8 +341,8 @@ function create($model = null, $options = array()) {
* @link http://book.cakephp.org/view/1389/Closing-the-Form
*/
public function end($options = null) {
if (!empty($this->params['models'])) {
$models = $this->params['models'][0];
if (!empty($this->request['models'])) {
$models = $this->request['models'][0];
}
$out = null;
$submit = null;
Expand All @@ -364,7 +364,7 @@ public function end($options = null) {
}
$out .= $this->submit($submit, $submitOptions);
}
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
if (isset($this->request['_Token']) && !empty($this->request['_Token'])) {
$out .= $this->secure($this->fields);
$this->fields = array();
}
Expand All @@ -383,7 +383,7 @@ public function end($options = null) {
* @return string A hidden input field with a security hash
*/
public function secure($fields = array()) {
if (!isset($this->params['_Token']) || empty($this->params['_Token'])) {
if (!isset($this->request['_Token']) || empty($this->request['_Token'])) {
return;
}
$locked = array();
Expand Down Expand Up @@ -426,8 +426,8 @@ function __secure($field = null, $value = null) {
$field = Set::filter(explode('.', $field), true);
}

if (!empty($this->params['_Token']['disabledFields'])) {
foreach ((array)$this->params['_Token']['disabledFields'] as $disabled) {
if (!empty($this->request['_Token']['disabledFields'])) {
foreach ((array)$this->request['_Token']['disabledFields'] as $disabled) {
$disabled = explode('.', $disabled);
if (array_values(array_intersect($field, $disabled)) === $disabled) {
return;
Expand Down Expand Up @@ -2160,7 +2160,7 @@ protected function _initInputField($field, $options = array()) {
$secure = $options['secure'];
unset($options['secure']);
} else {
$secure = (isset($this->params['_Token']) && !empty($this->params['_Token']));
$secure = (isset($this->request['_Token']) && !empty($this->request['_Token']));
}
$result = parent::_initInputField($field, $options);

Expand Down

0 comments on commit c5dfd12

Please sign in to comment.