Browse Source

Revert "Merge branch 'app-plugin' into master."

This reverts commit 084799ed2a83834a34d94c0eeb74fbe020c2994d, reversing
changes made to 2ad2b21cdd8b3bdd4ec76c9792ca8384164c24f9.

I accidentally merged a branch based on 3.next into master. :(
Mark Story 9 years ago
parent
commit
dc24d06961

+ 6 - 12
src/View/View.php

@@ -475,21 +475,18 @@ class View implements EventDispatcherInterface
      * - `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 @@ class View implements EventDispatcherInterface
      * 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 @@ class View implements EventDispatcherInterface
         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 @@ class View implements EventDispatcherInterface
             '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'];
 

+ 7 - 10
tests/TestCase/View/ViewTest.php

@@ -844,7 +844,7 @@ class ViewTest extends TestCase
         $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 @@ class ViewTest extends TestCase
         $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 @@ class ViewTest extends TestCase
         $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 @@ class ViewTest extends TestCase
         ], [
             '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');

+ 1 - 1
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]

+ 1 - 0
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

+ 0 - 1
tests/test_app/TestApp/Template/Element/plugin_element.ctp

@@ -1 +0,0 @@
-Plugin element overridden in app