Skip to content

Commit

Permalink
Add a way to reset templates on the FormHelper.
Browse files Browse the repository at this point in the history
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 dbe809b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/View/Helper/FormHelper.php
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -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.