Skip to content

Commit

Permalink
Correct order of themed plugin paths.
Browse files Browse the repository at this point in the history
The themed plugin path should precede the generic theme path. This makes
it possible for a plugin to provide specific views for specific
controllers even when plugins contain controllers of the same name.

Refs #4064
  • Loading branch information
markstory committed Jul 25, 2014
1 parent b8a7b0a commit a084fce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
14 changes: 4 additions & 10 deletions src/View/View.php
Expand Up @@ -932,11 +932,9 @@ protected function _paths($plugin = null, $cached = true) {
}
$paths = array();
$viewPaths = App::path('Template');
$corePaths = App::core('Template');

if (!empty($plugin)) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
for ($i = 0, $count = count($viewPaths); $i < $count; $i++) {
$paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
}
$paths = array_merge($paths, App::path('Template', $plugin));
Expand All @@ -948,21 +946,17 @@ protected function _paths($plugin = null, $cached = true) {
$themePaths = App::path('Template', $theme);

if ($plugin) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
$themePaths[] = $themePaths[$i] . 'Plugin' . DS . $plugin . DS;
for ($i = 0, $count = count($viewPaths); $i < $count; $i++) {
array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DS . $plugin . DS);
}
}

$paths = array_merge($themePaths, $paths);
}

$paths = array_merge($paths, $corePaths);
$paths = array_merge($paths, App::core('Template'));

if ($plugin !== null) {
return $this->_pathsForPlugin[$plugin] = $paths;
}

return $this->_paths = $paths;
}

Expand Down
30 changes: 29 additions & 1 deletion tests/TestCase/View/ViewTest.php
Expand Up @@ -422,7 +422,7 @@ public function testPluginThemedGetTemplate() {
*
* @return void
*/
public function testPluginPathGeneration() {
public function testPathPluginGeneration() {
$viewOptions = ['plugin' => 'TestPlugin',
'name' => 'TestPlugin',
'viewPath' => 'Tests',
Expand All @@ -445,6 +445,34 @@ public function testPluginPathGeneration() {
$this->assertPathEquals($expected, $paths);
}

/**
* Test that themed plugin paths are generated correctly.
*
* @return void
*/
public function testPathThemedPluginGeneration() {
$viewOptions = ['plugin' => 'TestPlugin',
'name' => 'TestPlugin',
'viewPath' => 'Tests',
'view' => 'index',
'theme' => 'TestTheme'
];

$View = new TestView(null, null, null, $viewOptions);
$paths = $View->paths('TestPlugin');
$pluginPath = Plugin::path('TestPlugin');
$themePath = Plugin::path('TestTheme');
$expected = array(
$themePath . 'src' . DS . 'Template' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
$themePath . 'src' . DS . 'Template' . DS,
TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
$pluginPath . 'src' . DS . 'Template' . DS,
TEST_APP . 'TestApp' . DS . 'Template' . DS,
CAKE . 'Template' . DS,
);
$this->assertPathEquals($expected, $paths);
}

/**
* Test that CamelCase'd plugins still find their view files.
*
Expand Down

0 comments on commit a084fce

Please sign in to comment.