Refactoring themes/views to use a centralized location instead of allowing plugins to have themes.

The plugin should include all required views/assets, to override these at the application level using themes you would create:
<app_name>/views/themed/<theme_name>/<plugin_name>/<controller_name>/*.ctp

if you are not using themes you can override them at the app view level:
<app_name>/views/<plugin_name>/<controller_name>/*.ctp
This commit is contained in:
phpnut 2009-11-25 22:29:54 -06:00
parent 2eb85ef558
commit 21eb001a96
5 changed files with 13 additions and 6 deletions

View file

@ -55,7 +55,14 @@ class ThemeView extends View {
if (!empty($this->theme)) {
$count = count($paths);
for ($i = 0; $i < $count; $i++) {
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
if (strpos($paths[$i], DS . 'plugins' . DS) === false
&& strpos($paths[$i], DS . 'libs' . DS . 'view') === false
&& strpos($paths[$i], DS . $plugin . DS) === false) {
if ($plugin) {
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . $plugin . DS;
}
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
}
}
$paths = array_merge($themePaths, $paths);
}

View file

@ -939,7 +939,7 @@ class View extends Object {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
if (!isset($corePaths[$viewPaths[$i]])) {
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
$paths[] = $viewPaths[$i] . $plugin . DS;
}
}
$paths[] = App::pluginPath($plugin) . 'views' . DS;

View file

@ -199,19 +199,19 @@ class ThemeViewTest extends CakeTestCase {
* @access public
* @return void
*/
function testPluginGetTemplate() {
function testPluginThemedGetTemplate() {
$this->Controller->plugin = 'test_plugin';
$this->Controller->name = 'TestPlugin';
$this->Controller->viewPath = 'tests';
$this->Controller->action = 'index';
$this->Controller->theme = 'test_plugin_theme';
$this->Controller->theme = 'test_theme';
$ThemeView = new TestThemeView($this->Controller);
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS .'tests' . DS .'index.ctp';
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'test_plugin' . DS . 'tests' . DS .'index.ctp';
$result = $ThemeView->getViewFileName('index');
$this->assertEqual($result, $expected);
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS . 'layouts' . DS .'default.ctp';
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'test_plugin' . DS . 'layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName();
$this->assertEqual($result, $expected);
}