Browse Source

Add support for themes + cells.

Cells should inherit the current View's theme and use it correctly when
rendering.
mark_story 12 years ago
parent
commit
d1300885f0
3 changed files with 23 additions and 1 deletions
  1. 8 1
      src/View/Cell.php
  2. 1 0
      src/View/CellTrait.php
  3. 14 0
      tests/TestCase/View/CellTest.php

+ 8 - 1
src/View/Cell.php

@@ -79,6 +79,13 @@ abstract class Cell {
 	public $viewClass = 'Cake\View\View';
 	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
  * Instance of the Cake\Event\EventManager this cell is using
  * to dispatch inner events.
  * to dispatch inner events.
  *
  *
@@ -93,7 +100,7 @@ abstract class Cell {
  * @see \Cake\View\View
  * @see \Cake\View\View
  */
  */
 	protected $_validViewOptions = [
 	protected $_validViewOptions = [
-		'viewVars', 'helpers', 'viewPath', 'plugin',
+		'viewVars', 'helpers', 'viewPath', 'plugin', 'theme'
 	];
 	];
 
 
 /**
 /**

+ 1 - 0
src/View/CellTrait.php

@@ -73,6 +73,7 @@ trait CellTrait {
 		$cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options);
 		$cellInstance = new $className($this->request, $this->response, $this->getEventManager(), $options);
 		$cellInstance->action = Inflector::underscore($action);
 		$cellInstance->action = Inflector::underscore($action);
 		$cellInstance->plugin = !empty($plugin) ? $plugin : null;
 		$cellInstance->plugin = !empty($plugin) ? $plugin : null;
+		$cellInstance->theme = !empty($this->theme) ? $this->theme : null;
 		$length = count($data);
 		$length = count($data);
 
 
 		if ($length) {
 		if ($length) {

+ 14 - 0
tests/TestCase/View/CellTest.php

@@ -108,6 +108,20 @@ class CellTest extends TestCase {
 	}
 	}
 
 
 /**
 /**
+ * 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.
  * Tests that using plugin's cells works.
  *
  *
  * @return void
  * @return void