@@ -46,7 +46,6 @@ public function __construct(View $View, $options = array()) {
4646 $ viewPath = $ viewPath [0 ];
4747
4848 $ viewPath = $ this ->checkPluginPath ($ viewPath );
49-
5049 $ partialsPath = $ viewPath .'Elements ' ;
5150 $ this ->m = new Mustache_Engine (array (
5251 'partials_loader ' => new Mustache_Loader_FilesystemLoader ($ partialsPath ),
@@ -56,19 +55,37 @@ public function __construct(View $View, $options = array()) {
5655 /**
5756 * Take a path as default, and check if we should be looking in a plugin for elements instead.
5857 */
59- private function checkPluginPath ($ viewPath ) {
58+ private function checkPluginPath ($ viewPath, $ elementFile = null ) {
6059
6160 // check if we're in plugin and change partials path if we are
6261 if ($ plugin = $ this ->View ->plugin ) {
6362 $ pluginPath = App::path ('Plugin ' );
6463 $ pluginPath = $ pluginPath [0 ];
65- $ viewPath = $ pluginPath .$ plugin .'/View/ ' ;
64+
65+ $ pluginElementPath = $ pluginPath .$ plugin .'/View/ ' ;
66+
67+ if ($ elementFile and $ this ->checkPluginElement ($ pluginElementPath .$ elementFile )) {
68+ $ viewPath = $ pluginPath .$ plugin .'/View/ ' ;
69+ }
6670 }
67-
6871 return $ viewPath ;
6972
7073 }
7174
75+
76+ private function checkPluginElement ($ elementPath ) {
77+
78+ if (!file_exists ($ elementPath )) {
79+ $ viewPath = App::path ('View ' );
80+ $ viewPath = $ viewPath [0 ];
81+ $ this ->m = new Mustache_Engine (array (
82+ 'partials_loader ' => new Mustache_Loader_FilesystemLoader ($ viewPath ),
83+ ));
84+ return false ;
85+ }
86+ return true ;
87+ }
88+
7289 /** Returns the rendered template as HTML.
7390 * All variables should be 'set' by the CakePHP Controller
7491 *
@@ -130,10 +147,11 @@ private function _getElementPath( $element ) {
130147 $ element = str_replace ('__ ' , '/ ' , $ element );
131148 $ app_path = App::path ('View ' );
132149 $ app_path = $ app_path [0 ];
150+ $ elementFile = $ element . '. ' . $ this ->ext ;
133151
134- $ app_path = $ this ->checkPluginPath ($ app_path );
152+ $ app_path = $ this ->checkPluginPath ($ app_path, $ elementFile );
135153
136- return $ app_path . 'Elements ' . DS . $ element . ' . ' . $ this -> ext ;
154+ return $ app_path . 'Elements ' . DS . $ elementFile ;
137155 }
138156
139157
0 commit comments