Skip to content

Commit

Permalink
Add support for themes + cells.
Browse files Browse the repository at this point in the history
Cells should inherit the current View's theme and use it correctly when
rendering.
  • Loading branch information
markstory committed Apr 27, 2014
1 parent 73a65e1 commit d130088
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/View/Cell.php
Expand Up @@ -78,6 +78,13 @@ abstract class Cell {
*/
public $viewClass = 'Cake\View\View';

/**
* The theme name that will be used to render.
*
* @var string
*/
public $theme;

/**
* Instance of the Cake\Event\EventManager this cell is using
* to dispatch inner events.
Expand All @@ -93,7 +100,7 @@ abstract class Cell {
* @see \Cake\View\View
*/
protected $_validViewOptions = [
'viewVars', 'helpers', 'viewPath', 'plugin',
'viewVars', 'helpers', 'viewPath', 'plugin', 'theme'
];

/**
Expand Down
1 change: 1 addition & 0 deletions src/View/CellTrait.php
Expand Up @@ -73,6 +73,7 @@ public function cell($cell, $data = [], $options = []) {
$cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options);
$cellInstance->action = Inflector::underscore($action);
$cellInstance->plugin = !empty($plugin) ? $plugin : null;
$cellInstance->theme = !empty($this->theme) ? $this->theme : null;
$length = count($data);

if ($length) {
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/View/CellTest.php
Expand Up @@ -107,6 +107,20 @@ public function testCellManualRender() {
$this->assertContains('<h2>Lorem ipsum</h2>', $cell->render('teaser_list'));
}

/**
* Test rendering a cell with a theme.
*
* @return void
*/
public function testCellRenderThemed() {
$this->View->theme = 'TestTheme';
$cell = $this->View->cell('Articles', ['msg' => 'hello world!']);

$this->assertEquals($this->View->theme, $cell->theme);
$this->assertContains('Themed cell content.', $cell->render());
$this->assertEquals($cell->View->theme, $cell->theme);
}

/**
* Tests that using plugin's cells works.
*
Expand Down

0 comments on commit d130088

Please sign in to comment.