Skip to content

Commit

Permalink
Revert "Merge branch 'app-plugin' into master."
Browse files Browse the repository at this point in the history
This reverts commit 084799e, reversing
changes made to 2ad2b21.

I accidentally merged a branch based on 3.next into master. :(
  • Loading branch information
markstory committed Sep 16, 2016
1 parent 084799e commit dc24d06
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
18 changes: 6 additions & 12 deletions src/View/View.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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),
Expand All @@ -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'];

Expand Down
17 changes: 7 additions & 10 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -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);
}

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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', [
Expand All @@ -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');
Expand Down
@@ -1 +1 @@
Element in the TestPlugin
this is the plugin element using params[plugin]
@@ -0,0 +1 @@
this is the test set using View::$plugin plugin element
1 change: 0 additions & 1 deletion tests/test_app/TestApp/Template/Element/plugin_element.ctp

This file was deleted.

0 comments on commit dc24d06

Please sign in to comment.