From ad62e779c88ce41ab6b026b127797b37fcc5101f Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Mar 2014 18:06:35 -0400 Subject: [PATCH] Separate default templates and runtime templates. This makes for fewer workarounds with managing templates vs. having duplicate conditions for handling string/array templates. Refs #3142 --- src/View/Helper/FormHelper.php | 7 +++---- src/View/Helper/PaginatorHelper.php | 2 +- src/View/Helper/SessionHelper.php | 2 +- src/View/Helper/StringTemplateTrait.php | 4 +++- tests/TestCase/View/Helper/FormHelperTest.php | 16 ++++++++++++++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 37b252f91f1..d4dcf9b4de9 100755 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -76,7 +76,7 @@ class FormHelper extends Helper { ], 'widgets' => [], 'registry' => null, - 'templates' => [ + 'defaultTemplates' => [ 'button' => '{{text}}', 'checkbox' => '', 'checkboxContainer' => '
{{input}}{{label}}
', @@ -168,9 +168,8 @@ class FormHelper extends Helper { * @param \Cake\View\View $View The View this helper is being attached to. * @param array $config Configuration settings for the helper. */ - public function __construct(View $View, $config = array()) { + public function __construct(View $View, $config = []) { parent::__construct($View, $config); - $config = $this->config(); $this->widgetRegistry($config['registry'], $config['widgets']); @@ -2238,7 +2237,7 @@ public function widget($name, array $data = []) { * @return void */ public function resetTemplates() { - $this->templates($this->_defaultConfig['templates']); + $this->templates($this->_defaultConfig['defaultTemplates']); } /** diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index 72fa3f9aab4..42b89c013d2 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -49,7 +49,7 @@ class PaginatorHelper extends Helper { */ protected $_defaultConfig = [ 'options' => [], - 'templates' => [ + 'defaultTemplates' => [ 'nextActive' => '', 'nextDisabled' => '', 'prevActive' => '', diff --git a/src/View/Helper/SessionHelper.php b/src/View/Helper/SessionHelper.php index 25287f6d8d3..edaf09f1c5a 100644 --- a/src/View/Helper/SessionHelper.php +++ b/src/View/Helper/SessionHelper.php @@ -36,7 +36,7 @@ class SessionHelper extends Helper { * @var array */ protected $_defaultConfig = [ - 'templates' => [ + 'defaultTemplates' => [ 'flash' => '
{{message}}
' ] ]; diff --git a/src/View/Helper/StringTemplateTrait.php b/src/View/Helper/StringTemplateTrait.php index a0cb08e6df9..a4a0a04a759 100644 --- a/src/View/Helper/StringTemplateTrait.php +++ b/src/View/Helper/StringTemplateTrait.php @@ -66,8 +66,10 @@ public function templater() { $class = $this->config('templateClass') ?: '\Cake\View\StringTemplate'; $this->_templater = new $class; - $templates = $this->config('templates'); + $defaults = $this->config('defaultTemplates'); + $this->_templater->add($defaults); + $templates = $this->config('templates'); if ($templates) { if (is_string($templates)) { $this->_templater->load($templates); diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index 8146b5b055d..4667454cd12 100755 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -143,7 +143,6 @@ public function setUp() { $this->View = new View(null); $this->Form = new FormHelper($this->View); - $this->Form->Html = new HtmlHelper($this->View); $this->Form->request = new Request('articles/add'); $this->Form->request->here = '/articles/add'; $this->Form->request['controller'] = 'articles'; @@ -187,10 +186,23 @@ public function setUp() { */ public function tearDown() { parent::tearDown(); - unset($this->Form->Html, $this->Form, $this->Controller, $this->View); + unset($this->Form, $this->Controller, $this->View); TableRegistry::clear(); } +/** + * Test construct() with the templates option. + * + * @return void + */ + public function testConstructTemplatesFile() { + $helper = new FormHelper($this->View, [ + 'templates' => 'htmlhelper_tags.php' + ]); + $result = $helper->input('name'); + $this->assertContains('