From 21eb001a9657b6ffe9bc80fb352969819e4b3606 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 25 Nov 2009 22:29:54 -0600 Subject: [PATCH] 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: /views/themed////*.ctp if you are not using themes you can override them at the app view level: /views///*.ctp --- cake/libs/view/theme.php | 9 ++++++++- cake/libs/view/view.php | 2 +- cake/tests/cases/libs/view/theme.test.php | 8 ++++---- .../themed/test_theme/test_plugin}/layouts/default.ctp | 0 .../themed/test_theme/test_plugin}/tests/index.ctp | 0 5 files changed, 13 insertions(+), 6 deletions(-) rename cake/tests/test_app/{plugins/test_plugin/views/themed/test_plugin_theme => views/themed/test_theme/test_plugin}/layouts/default.ctp (100%) rename cake/tests/test_app/{plugins/test_plugin/views/themed/test_plugin_theme => views/themed/test_theme/test_plugin}/tests/index.ctp (100%) diff --git a/cake/libs/view/theme.php b/cake/libs/view/theme.php index a5df7f740..c2531f442 100644 --- a/cake/libs/view/theme.php +++ b/cake/libs/view/theme.php @@ -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); } diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 854bcc1e5..f25c84838 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -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; diff --git a/cake/tests/cases/libs/view/theme.test.php b/cake/tests/cases/libs/view/theme.test.php index 83cb4ef8c..a40b2323b 100644 --- a/cake/tests/cases/libs/view/theme.test.php +++ b/cake/tests/cases/libs/view/theme.test.php @@ -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); } diff --git a/cake/tests/test_app/plugins/test_plugin/views/themed/test_plugin_theme/layouts/default.ctp b/cake/tests/test_app/views/themed/test_theme/test_plugin/layouts/default.ctp similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/views/themed/test_plugin_theme/layouts/default.ctp rename to cake/tests/test_app/views/themed/test_theme/test_plugin/layouts/default.ctp diff --git a/cake/tests/test_app/plugins/test_plugin/views/themed/test_plugin_theme/tests/index.ctp b/cake/tests/test_app/views/themed/test_theme/test_plugin/tests/index.ctp similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/views/themed/test_plugin_theme/tests/index.ctp rename to cake/tests/test_app/views/themed/test_theme/test_plugin/tests/index.ctp