diff --git a/src/View/Cell.php b/src/View/Cell.php index 0f83ee3194b..b10cb909419 100644 --- a/src/View/Cell.php +++ b/src/View/Cell.php @@ -40,13 +40,12 @@ abstract class Cell { public $View; /** - * Name of the action that was invoked. - * - * Action name will be inflected to get the template name when rendering. + * Name of the template that will be rendered. + * This property is inflected from the action name that was invoked. * * @var string */ - public $action; + public $template; /** * Automatically set to the name of a plugin. @@ -137,13 +136,16 @@ public function __construct(Request $request = null, Response $response = null, /** * Render the cell. * - * @param string $action Custom template name to render. If not provided (null), the last + * @param string $template Custom template name to render. If not provided (null), the last * value will be used. This value is automatically set by `CellTrait::cell()`. * @return void */ - public function render($action = null) { - if ($action !== null) { - $this->action = $action; + public function render($template = null) { + if ($template !== null) { + $template = Inflector::underscore($template); + } + if (empty($template)) { + $template = $this->template; } $this->View = $this->createView(); @@ -153,7 +155,7 @@ public function render($action = null) { $className = array_pop($className); $this->View->subDir = 'Cell' . DS . substr($className, 0, strpos($className, 'Cell')); - return $this->View->render(Inflector::underscore($this->action)); + return $this->View->render($template); } /** @@ -175,7 +177,7 @@ public function __toString() { public function __debugInfo() { return [ 'plugin' => $this->plugin, - 'action' => $this->action, + 'template' => $this->template, 'viewClass' => $this->viewClass, 'request' => $this->request, 'response' => $this->response, diff --git a/src/View/CellTrait.php b/src/View/CellTrait.php index d6722b88608..654dedf9ac5 100644 --- a/src/View/CellTrait.php +++ b/src/View/CellTrait.php @@ -71,7 +71,7 @@ public function cell($cell, $data = [], $options = []) { } $cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options); - $cellInstance->action = Inflector::underscore($action); + $cellInstance->template = Inflector::underscore($action); $cellInstance->plugin = !empty($plugin) ? $plugin : null; $cellInstance->theme = !empty($this->theme) ? $this->theme : null; $length = count($data); diff --git a/tests/TestCase/View/CellTest.php b/tests/TestCase/View/CellTest.php index 19c84d333dd..a58358a524f 100644 --- a/tests/TestCase/View/CellTest.php +++ b/tests/TestCase/View/CellTest.php @@ -64,6 +64,7 @@ public function testCellRender() { $cell = $this->View->cell('Articles::teaserList'); $render = "{$cell}"; + $this->assertEquals('teaser_list', $cell->template); $this->assertContains('

Lorem ipsum

', $render); $this->assertContains('

Usectetur adipiscing eli

', $render); $this->assertContains('

Topis semper blandit eu non

', $render); @@ -88,10 +89,13 @@ public function testCellWithArguments() { */ public function testDefaultCellAction() { $appCell = $this->View->cell('Articles'); + + $this->assertEquals('display', $appCell->template); $this->assertContains('dummy', "{$appCell}"); $pluginCell = $this->View->cell('TestPlugin.Dummy'); $this->assertContains('dummy', "{$pluginCell}"); + $this->assertEquals('display', $pluginCell->template); } /**