From 1b19ad48b4dd4a3319f84fa8ab89605b68bc55d2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 4 Nov 2010 22:53:00 -0400 Subject: [PATCH] Adding parameters to helper callbacks, these allow helpers to introspect more on the view/layout being rendered. Updating tests. --- cake/libs/view/helper.php | 14 ++++++++++---- cake/libs/view/helpers/paginator.php | 4 ++-- cake/libs/view/view.php | 8 ++++---- .../cases/libs/view/helpers/paginator.test.php | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 43a7ecbcd05..e435ed067a6 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -801,9 +801,10 @@ public function output($str) { * * Overridden in subclasses. * + * @param string $viewFile The view file that is going to be rendered * @return void */ - public function beforeRender() { + public function beforeRender($viewFile) { } /** @@ -812,9 +813,11 @@ public function beforeRender() { * * Overridden in subclasses. * + * @param string $viewFile The view file that was rendered. + * @param string $content The content of the rendered view. * @return void */ - public function afterRender() { + public function afterRender($viewFile, $content) { } /** @@ -822,9 +825,10 @@ public function afterRender() { * * Overridden in subclasses. * + * @param string $layoutFile The layout about to be rendered. * @return void */ - public function beforeLayout() { + public function beforeLayout($layoutFile) { } /** @@ -832,9 +836,11 @@ public function beforeLayout() { * * Overridden in subclasses. * + * @param string $layoutFile The layout file that was rendered. + * @param string $content The content of the rendered layout. * @return void */ - public function afterLayout() { + public function afterLayout($layoutFile, $content) { } /** diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index d20f89481bc..a9b3b32ed7b 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -110,10 +110,10 @@ function __construct(View $View, $settings = array()) { * * @return void */ - public function beforeRender() { + public function beforeRender($viewFile) { $this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']); - parent::beforeRender(); + parent::beforeRender($viewFile); } /** diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 8fac92859fd..f0bdb4e4e79 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -391,9 +391,9 @@ public function render($action = null, $layout = null, $file = null) { } if ($action !== false && $viewFileName = $this->_getViewFileName($action)) { - $this->Helpers->trigger('beforeRender', array($this, $viewFileName)); + $this->Helpers->trigger('beforeRender', array($viewFileName)); $out = $this->_render($viewFileName); - $this->Helpers->trigger('afterRender', array($this, $viewFileName, $out)); + $this->Helpers->trigger('afterRender', array($viewFileName, $out)); } if ($layout === null) { @@ -437,7 +437,7 @@ public function renderLayout($content_for_layout, $layout = null) { if (!$this->_helpersLoaded) { $this->loadHelpers(); } - $this->Helpers->trigger('beforeLayout', array(&$this, $layoutFileName)); + $this->Helpers->trigger('beforeLayout', array($layoutFileName)); $this->viewVars = array_merge($this->viewVars, array( 'content_for_layout' => $content_for_layout, @@ -454,7 +454,7 @@ public function renderLayout($content_for_layout, $layout = null) { throw new RuntimeException(sprintf(__("Error in layout %s, got no content."), $layoutFileName)); } - $this->Helpers->trigger('afterLayout', array(&$this, $layoutFileName, $this->output)); + $this->Helpers->trigger('afterLayout', array($layoutFileName, $this->output)); return $this->output; } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index e4a30f2684e..101f5395f2e 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -657,7 +657,7 @@ function testPassedArgsMergingWithUrlOptions() { $this->Paginator->request->params['pass'] = array(2); $this->Paginator->request->params['named'] = array('foo' => 'bar'); - $this->Paginator->beforeRender(); + $this->Paginator->beforeRender('posts/index'); $result = $this->Paginator->sort('title'); $expected = array(