Browse Source

Fix issue with inputs() and plugin models.

inputs() should not trigger errors when generating inputs for plugin
models. Previously the internal state of FormHelper was incorrect as
model() returned the plugin name instead of the modelname.

Fixes #3571
mark_story 13 years ago
parent
commit
78b23d8e31

+ 25 - 0
lib/Cake/Test/Case/View/Helper/FormHelperTest.php

@@ -2997,6 +2997,31 @@ class FormHelperTest extends CakeTestCase {
 	}
 
 /**
+ * Tests inputs() works with plugin models
+ *
+ * @return void
+ */
+	public function testInputsPluginModel() {
+		$this->loadFixtures('Post');
+		App::build(array(
+			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
+		));
+		CakePlugin::load('TestPlugin');
+		$this->Form->request['models'] = array(
+			'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
+		);
+		$this->Form->create('TestPlugin.TestPluginPost');
+		$result = $this->Form->inputs();
+
+		$this->assertContains('data[TestPluginPost][id]', $result);
+		$this->assertContains('data[TestPluginPost][author_id]', $result);
+		$this->assertContains('data[TestPluginPost][title]', $result);
+		$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
+		$this->assertFalse(ClassRegistry::isKeySet('TestPlugin'));
+		$this->assertEquals('TestPluginPost', $this->Form->model());
+	}
+
+/**
  * testSelectAsCheckbox method
  *
  * test multi-select widget with checkbox formatting.

+ 2 - 1
lib/Cake/View/Helper/FormHelper.php

@@ -329,7 +329,8 @@ class FormHelper extends AppHelper {
 
 		$key = null;
 		if ($model !== false) {
-			$key = $this->_introspectModel($model, 'key');
+			list($plugin, $model) = pluginSplit($model, true);
+			$key = $this->_introspectModel($plugin . $model, 'key');
 			$this->setEntity($model, true);
 		}