Browse files

Add a way to reset templates on the FormHelper.

Now that there are multiple ways to mutate the templates at runtime,
having a way to restore any edits will probably come in handy.
  • Loading branch information...
1 parent 3100338 commit dbe809b3f8e4b3ca95fecc08f777f0d66f768f47 @markstory markstory committed with markstory Mar 9, 2014
Showing with 26 additions and 0 deletions.
  1. +13 −0 src/View/Helper/FormHelper.php
  2. +13 −0 tests/TestCase/View/Helper/FormHelperTest.php
View
13 src/View/Helper/FormHelper.php
@@ -2233,6 +2233,19 @@ public function widget($name, array $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.
*
* @return array
View
13 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' => '<input>']);
+ $this->assertEquals('<input>', $this->Form->getTemplater()->get('input'));
+
+ $this->assertNull($this->Form->resetTemplates());
+ $this->assertNotEquals('<input>', $this->Form->getTemplater()->get('input'));
+ }
+
}

0 comments on commit dbe809b

Please sign in to comment.