Permalink
Browse files

Fixing Helper::value() and extraction of habtm data. Refs #256

  • Loading branch information...
1 parent b974127 commit 380b49a446d5d87ebb8075b887027e17150b7357 @markstory markstory committed Nov 4, 2009
Showing with 13 additions and 5 deletions.
  1. +11 −3 cake/libs/view/helper.php
  2. +2 −2 cake/tests/cases/libs/view/helper.test.php
View
@@ -544,7 +544,7 @@ function tagIsInvalid($model = null, $field = null, $modelID = null) {
$errors = $this->validationErrors;
$entity = $view->entity();
if (!empty($entity)) {
- return Set::extract($errors,join('.',$entity));
+ return Set::extract($errors, join('.', $entity));
}
}
@@ -645,10 +645,18 @@ function value($options = array(), $field = null, $key = 'value') {
$view =& ClassRegistry::getObject('view');
$result = null;
-
+
$entity = $view->entity();
if (!empty($this->data) && !empty($entity)) {
- $result = Set::extract($this->data,join('.',$entity));
+ $result = Set::extract($this->data, join('.', $entity));
+ }
+
+ $habtmKey = $this->field();
+ if (empty($result) && isset($this->data[$habtmKey]) && is_array($this->data[$habtmKey])) {
+ if (ClassRegistry::isKeySet($habtmKey)) {
+ $model =& ClassRegistry::getObject($habtmKey);
+ $result = $this->__selectedArray($this->data[$habtmKey], $model->primaryKey);
+ }
}
if (is_array($result)) {
@@ -538,11 +538,11 @@ function testFieldSuffixForDate() {
*/
function testMulitDimensionValue() {
$this->Helper->data = array();
- for($i = 0; $i < 2; $i++) {
+ for ($i = 0; $i < 2; $i++) {
$this->Helper->data['Model'][$i] = 'what';
$result[] = $this->Helper->value("Model.{$i}");
$this->Helper->data['Model'][$i] = array();
- for($j = 0; $j < 2; $j++) {
+ for ($j = 0; $j < 2; $j++) {
$this->Helper->data['Model'][$i][$j] = 'how';
$result[] = $this->Helper->value("Model.{$i}.{$j}");
}

0 comments on commit 380b49a

Please sign in to comment.