Skip to content

Commit

Permalink
Adding settings['callbacks'] as a way to define enabled/disabled stat…
Browse files Browse the repository at this point in the history
…e of helpers in settings arrays. This should replace the separate parameter.

Tests updated.
  • Loading branch information
markstory committed Nov 7, 2010
1 parent 92fec45 commit 1ba28c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cake/libs/view/helper_collection.php
Expand Up @@ -38,6 +38,9 @@ public function __construct(View $view) {

/**
* 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.
Expand Down Expand Up @@ -72,7 +75,7 @@ public function load($helper, $settings = array(), $enable = true) {
foreach ($vars as $var) {
$this->_loaded[$name]->{$var} = $this->_View->{$var};
}

$enable = isset($settings['callbacks']) ? $settings['callbacks'] : $enable;
if ($enable === true) {
$this->_enabled[] = $name;
}
Expand Down
14 changes: 14 additions & 0 deletions cake/tests/cases/libs/view/helper_collection.test.php
Expand Up @@ -69,6 +69,20 @@ function testLoadWithEnableFalse() {

$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
*
Expand Down

0 comments on commit 1ba28c2

Please sign in to comment.