diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 97e15fe8fa5..835d1f28c7e 100755 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -2232,6 +2232,19 @@ public function widget($name, array $data = []) { return $this->_registry->get($name)->render($data); } +/** + * Restores the default values built into FormHelper. + * + * This method will not reset any templates set in custom widgets. + * + * @return void + */ + public function resetTemplates() { + $reflection = new \ReflectionClass($this); + $properties = $reflection->getDefaultProperties(); + $this->templates($properties['_defaultTemplates']); + } + /** * Event listeners. * diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index 6b0dd5aefa7..204d9b8ff41 100755 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -5770,4 +5770,17 @@ public function testNestInputInLabel() { $this->assertTags($result, $expected); } +/** + * Test resetting templates. + * + * @return void + */ + public function testResetTemplates() { + $this->Form->templates(['input' => '']); + $this->assertEquals('', $this->Form->getTemplater()->get('input')); + + $this->assertNull($this->Form->resetTemplates()); + $this->assertNotEquals('', $this->Form->getTemplater()->get('input')); + } + }