diff --git a/src/View/View.php b/src/View/View.php index 74f2224112b..16254f6d8a4 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -475,21 +475,18 @@ public function layout($name = null) * - `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element. * Defaults to false. * - `ignoreMissing` - Used to allow missing elements. Set to true to not throw exceptions. - * - `plugin` - setting to false will force to use the application's element from plugin templates, when the - * plugin has element with same name. Defaults to true * @return string Rendered Element * @throws \Cake\View\Exception\MissingElementException When an element is missing and `ignoreMissing` * is false. */ public function element($name, array $data = [], array $options = []) { - $options += ['callbacks' => false, 'cache' => null, 'plugin' => null]; + $options += ['callbacks' => false, 'cache' => null]; if (isset($options['cache'])) { $options['cache'] = $this->_elementCache($name, $data, $options); } - $pluginCheck = $options['plugin'] === false ? false : true; - $file = $this->_getElementFilename($name, $pluginCheck); + $file = $this->_getElementFileName($name); if ($file && $options['cache']) { return $this->cache(function () use ($file, $data, $options) { echo $this->_renderElement($file, $data, $options); @@ -1194,12 +1191,11 @@ protected function _getLayoutFileName($name = null) * Finds an element filename, returns false on failure. * * @param string $name The name of the element to find. - * @param bool $pluginCheck - if false will ignore the request's plugin if parsed plugin is not loaded * @return string|false Either a string to the element filename or false when one can't be found. */ - protected function _getElementFileName($name, $pluginCheck = true) + protected function _getElementFileName($name) { - list($plugin, $name) = $this->pluginSplit($name, $pluginCheck); + list($plugin, $name) = $this->pluginSplit($name); $paths = $this->_paths($plugin); $elementPaths = $this->_getSubPaths('Element'); @@ -1312,8 +1308,6 @@ protected function _elementCache($name, $data, $options) if ($plugin) { $underscored = Inflector::underscore($plugin); } - $cache = $options['cache']; - unset($options['cache'], $options['callbacks'], $options['plugin']); $keys = array_merge( [$underscored, $name], array_keys($options), @@ -1323,12 +1317,12 @@ protected function _elementCache($name, $data, $options) 'config' => $this->elementCache, 'key' => implode('_', $keys) ]; - if (is_array($cache)) { + if (is_array($options['cache'])) { $defaults = [ 'config' => $this->elementCache, 'key' => $config['key'] ]; - $config = $cache + $defaults; + $config = $options['cache'] + $defaults; } $config['key'] = 'element_' . $config['key']; diff --git a/tests/TestCase/View/ViewTest.php b/tests/TestCase/View/ViewTest.php index f75f1c3dfe5..206054b8c39 100644 --- a/tests/TestCase/View/ViewTest.php +++ b/tests/TestCase/View/ViewTest.php @@ -844,7 +844,7 @@ public function testElementExists() $this->assertFalse($result); $this->View->plugin = 'TestPlugin'; - $result = $this->View->elementExists('plugin_element'); + $result = $this->View->elementExists('test_plugin_element'); $this->assertTrue($result); } @@ -859,14 +859,11 @@ public function testElement() $this->assertEquals('this is the test element', $result); $result = $this->View->element('TestPlugin.plugin_element'); - $this->assertEquals("Element in the TestPlugin\n", $result); + $this->assertEquals('this is the plugin element using params[plugin]', $result); $this->View->plugin = 'TestPlugin'; - $result = $this->View->element('plugin_element'); - $this->assertEquals("Element in the TestPlugin\n", $result); - - $result = $this->View->element('plugin_element', [], ['plugin' => false]); - $this->assertEquals("Plugin element overridden in app\n", $result); + $result = $this->View->element('test_plugin_element'); + $this->assertEquals('this is the test set using View::$plugin plugin element', $result); } /** @@ -992,13 +989,13 @@ public function testElementCache() $expected = 'this is the test element'; $this->assertEquals($expected, $result); - $result = Cache::read('element__test_element', 'test_view'); + $result = Cache::read('element__test_element_cache_callbacks', 'test_view'); $this->assertEquals($expected, $result); $result = $View->element('test_element', ['param' => 'one', 'foo' => 'two'], ['cache' => true]); $this->assertEquals($expected, $result); - $result = Cache::read('element__test_element_param_foo', 'test_view'); + $result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view'); $this->assertEquals($expected, $result); $View->element('test_element', [ @@ -1017,7 +1014,7 @@ public function testElementCache() ], [ 'cache' => ['config' => 'test_view'], ]); - $result = Cache::read('element__test_element_param_foo', 'test_view'); + $result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view'); $this->assertEquals($expected, $result); Cache::clear(true, 'test_view'); diff --git a/tests/test_app/Plugin/TestPlugin/src/Template/Element/plugin_element.ctp b/tests/test_app/Plugin/TestPlugin/src/Template/Element/plugin_element.ctp index 27e4dc015a4..3fcb903476d 100644 --- a/tests/test_app/Plugin/TestPlugin/src/Template/Element/plugin_element.ctp +++ b/tests/test_app/Plugin/TestPlugin/src/Template/Element/plugin_element.ctp @@ -1 +1 @@ -Element in the TestPlugin +this is the plugin element using params[plugin] \ No newline at end of file diff --git a/tests/test_app/Plugin/TestPlugin/src/Template/Element/test_plugin_element.ctp b/tests/test_app/Plugin/TestPlugin/src/Template/Element/test_plugin_element.ctp new file mode 100644 index 00000000000..99cc002d28c --- /dev/null +++ b/tests/test_app/Plugin/TestPlugin/src/Template/Element/test_plugin_element.ctp @@ -0,0 +1 @@ +this is the test set using View::$plugin plugin element \ No newline at end of file diff --git a/tests/test_app/TestApp/Template/Element/plugin_element.ctp b/tests/test_app/TestApp/Template/Element/plugin_element.ctp deleted file mode 100644 index a9ce0ad9e4c..00000000000 --- a/tests/test_app/TestApp/Template/Element/plugin_element.ctp +++ /dev/null @@ -1 +0,0 @@ -Plugin element overridden in app