Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Start hidden and add array casts to fix issues with mocks.

Mocks return null. Having an array cast smoothes over PHP warnings.
  • Loading branch information...
commit e45cf77860a8105e4e01c27a06615bff1e4c601c 1 parent 5e234d4
@markstory markstory authored
View
2  src/View/Form/ArrayContext.php
@@ -190,7 +190,7 @@ public function attributes($field) {
if (!is_array($this->_context['schema'])) {
return [];
}
- $schema = Hash::get($this->_context['schema'], $field);
+ $schema = (array)Hash::get($this->_context['schema'], $field);
$whitelist = ['length' => null, 'precision' => null];
return array_intersect_key($schema, $whitelist);
}
View
2  src/View/Form/EntityContext.php
@@ -359,7 +359,7 @@ public function attributes($field) {
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
$table = $this->_getTable($prop);
- $column = $table->schema()->column(array_pop($parts));
+ $column = (array)$table->schema()->column(array_pop($parts));
$whitelist = ['length' => null, 'precision' => null];
return array_intersect_key($column, $whitelist);
}
View
42 src/View/Helper/FormHelper.php
@@ -63,6 +63,15 @@ class FormHelper extends Helper {
);
/**
+ * Settings for the helper.
+ *
+ * @var array
+ */
+ public $settings = [
+ 'errorClass' => 'form-error'
+ ];
+
+/**
* List of fields created, used with secure forms.
*
* @var array
@@ -163,6 +172,7 @@ class FormHelper extends Helper {
'formstart' => '<form{{attrs}}>',
'formend' => '</form>',
'hiddenblock' => '<div style="display:none;">{{content}}</div>',
+ 'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
];
/**
@@ -1588,7 +1598,8 @@ public function hidden($fieldName, $options = array()) {
$this->_secure(true, null, '' . $options['value']);
}
- return $this->Html->useTag('hidden', $options['name'], array_diff_key($options, array('name' => null)));
+ $options['type'] = 'hidden';
+ return $this->widget('hidden', $options);
}
/**
@@ -2808,7 +2819,7 @@ protected function _generateOptions($name, $options = array()) {
/**
* Sets field defaults and adds field to form security input hash.
- * Will also add a 'form-error' class if the field contains validation errors.
+ * Will also add the error class if the field contains validation errors.
*
* ### Options
*
@@ -2823,7 +2834,7 @@ protected function _generateOptions($name, $options = array()) {
* @param array $options Array of options to append options into.
* @return array Array of options for the input.
*/
- protected function _initInputField($field, $options = array()) {
+ protected function _initInputField($field, $options = []) {
if (isset($options['secure'])) {
$secure = $options['secure'];
unset($options['secure']);
@@ -2837,26 +2848,26 @@ protected function _initInputField($field, $options = array()) {
$options['disabled'] = true;
}
- $result = parent::_initInputField($field, $options);
- if ($this->tagIsInvalid() !== false) {
- $result = $this->addClass($result, 'form-error');
+ $options['val'] = $this->_context->val($field);
+ $options += $this->_context->attributes($field);
+
+ if ($this->_context->hasError($field)) {
+ $options = $this->addClass($options, $this->settings['errorClass']);
}
- if (!empty($result['disabled']) || $secure === static::SECURE_SKIP) {
- return $result;
+ if (!empty($options['disabled']) || $secure === static::SECURE_SKIP) {
+ return $options;
}
- if (!isset($result['required']) &&
- $this->_introspectModel($this->model(), 'validates', $this->field())
- ) {
- $result['required'] = true;
+ if (!isset($options['required']) && $this->_context->isRequired($field)) {
+ $options['required'] = true;
}
if ($secure === self::SECURE_SKIP) {
- return $result;
+ return $options;
}
$this->_secure($secure, $this->_secureFieldName($options));
- return $result;
+ return $options;
}
/**
@@ -2981,8 +2992,7 @@ public function addWidget($name, $spec) {
* @return void
*/
public function widget($name, array $data = []) {
- $widget = $this->_registry->get($name);
- return $widget->render($data);
+ return $this->_registry->get($name)->render($data);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.