Skip to content
Permalink
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...
markstory committed Mar 10, 2014
1 parent 3100338 commit dbe809b3f8e4b3ca95fecc08f777f0d66f768f47
Showing with 26 additions and 0 deletions.
  1. +13 −0 src/View/Helper/FormHelper.php
  2. +13 −0 tests/TestCase/View/Helper/FormHelperTest.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.
*
@@ -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.
You can’t perform that action at this time.