From c9acb6b587c45f98fb7dca7e150242c472859c7c Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 1 Jul 2011 07:39:03 -0400 Subject: [PATCH] Moving FormHelper specifics into that class. --- lib/Cake/Test/Case/View/HelperTest.php | 4 ---- lib/Cake/View/Helper/FormHelper.php | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index e784ca4b9..40a98903e 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -296,10 +296,6 @@ class HelperTest extends CakeTestCase { $this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist'); $expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist'); $this->assertEquals($expected, $this->Helper->entity()); - - $this->Helper->setEntity('HelperTestTag'); - $expected = array('HelperTestTag', 'HelperTestTag'); - $this->assertEquals($expected, $this->Helper->entity()); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a9c1c1da3..0725a1a25 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2098,6 +2098,26 @@ class FormHelper extends AppHelper { return $opt; } +/** + * Add support for special HABTM syntax. + * + * Sets this helper's model and field properties to the dot-separated value-pair in $entity. + * + * @param mixed $entity A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName" + * @param boolean $setScope Sets the view scope to the model specified in $tagValue + * @return void + */ + function setEntity($entity, $setScope = false) { + parent::setEntity($entity, $setScope); + $parts = explode('.', $entity); + if ( + isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) && + $this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' + ) { + $this->_entityPath = $parts[0] . '.' . $parts[0]; + } + } + /** * Gets the input field name for the current tag *