From 1ba28c246b0f8da0624bbf385182f704e9ce1acb Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 6 Nov 2010 14:58:27 -0400 Subject: [PATCH] Adding settings['callbacks'] as a way to define enabled/disabled state of helpers in settings arrays. This should replace the separate parameter. Tests updated. --- cake/libs/view/helper_collection.php | 5 ++++- .../cases/libs/view/helper_collection.test.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helper_collection.php b/cake/libs/view/helper_collection.php index 27f9d00bb..6640bb8a2 100644 --- a/cake/libs/view/helper_collection.php +++ b/cake/libs/view/helper_collection.php @@ -38,6 +38,9 @@ class HelperCollection extends ObjectCollection { /** * Loads/constructs a helper. Will return the instance in the registry if it already exists. + * By setting `$enable` to false you can disable callbacks for a helper. Alternatively you + * can set `$settings['callbacks'] = false` to disable callbacks. This alias is provided so that when + * declaring $helpers arrays you can disable callbacks on helpers. * * @param string $helper Helper name to load * @param array $settings Settings for the helper. @@ -72,7 +75,7 @@ class HelperCollection extends ObjectCollection { foreach ($vars as $var) { $this->_loaded[$name]->{$var} = $this->_View->{$var}; } - + $enable = isset($settings['callbacks']) ? $settings['callbacks'] : $enable; if ($enable === true) { $this->_enabled[] = $name; } diff --git a/cake/tests/cases/libs/view/helper_collection.test.php b/cake/tests/cases/libs/view/helper_collection.test.php index e0b586e2a..5d6dda543 100644 --- a/cake/tests/cases/libs/view/helper_collection.test.php +++ b/cake/tests/cases/libs/view/helper_collection.test.php @@ -69,6 +69,20 @@ class HelperCollectionTest extends CakeTestCase { $this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled'); } + +/** + * test that the callbacks setting disables the helper. + * + * @return void + */ + function testLoadWithCallbacksFalse() { + $result = $this->Helpers->load('Html', array('callbacks' => false)); + $this->assertType('HtmlHelper', $result); + $this->assertType('HtmlHelper', $this->Helpers->Html); + + $this->assertFalse($this->Helpers->enabled('Html'), 'Html should be disabled'); + } + /** * test missinghelper exception *