Moving FormHelper specifics into that class.

This commit is contained in:
mark_story 2011-07-01 07:39:03 -04:00
parent 89258327c6
commit c9acb6b587
2 changed files with 20 additions and 4 deletions

View file

@ -296,10 +296,6 @@ class HelperTest extends CakeTestCase {
$this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist'); $this->Helper->setEntity('ModelThatDoesntExist.field_that_doesnt_exist');
$expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist'); $expected = array('ModelThatDoesntExist', 'field_that_doesnt_exist');
$this->assertEquals($expected, $this->Helper->entity()); $this->assertEquals($expected, $this->Helper->entity());
$this->Helper->setEntity('HelperTestTag');
$expected = array('HelperTestTag', 'HelperTestTag');
$this->assertEquals($expected, $this->Helper->entity());
} }
/** /**

View file

@ -2098,6 +2098,26 @@ class FormHelper extends AppHelper {
return $opt; 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 * Gets the input field name for the current tag
* *