mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
accept dot syntax for element,view and layout filename from plugins fixes #2247
This commit is contained in:
parent
e4cc18c0e7
commit
a72ccf28e3
1 changed files with 33 additions and 4 deletions
|
@ -290,7 +290,8 @@ class View extends Object {
|
||||||
* This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send
|
* This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send
|
||||||
* data to be used in the element. Elements can be cached improving performance by using the `cache` option.
|
* data to be used in the element. Elements can be cached improving performance by using the `cache` option.
|
||||||
*
|
*
|
||||||
* @param string $name Name of template file in the/app/View/Elements/ folder
|
* @param string $name Name of template file in the/app/View/Elements/ folder,
|
||||||
|
* or `MyPlugin.template` to use the template element from MyPlugin , will be overriden by $options['plugin']
|
||||||
* @param array $data Array of data to be made available to the rendered view (i.e. the Element)
|
* @param array $data Array of data to be made available to the rendered view (i.e. the Element)
|
||||||
* @param array $options Array of options. Possible keys are:
|
* @param array $options Array of options. Possible keys are:
|
||||||
* - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
|
* - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
|
||||||
|
@ -308,6 +309,8 @@ class View extends Object {
|
||||||
|
|
||||||
if (isset($options['plugin'])) {
|
if (isset($options['plugin'])) {
|
||||||
$plugin = Inflector::camelize($options['plugin']);
|
$plugin = Inflector::camelize($options['plugin']);
|
||||||
|
} else {
|
||||||
|
list($plugin, $name) = $this->_pluginSplit($name);
|
||||||
}
|
}
|
||||||
if (isset($this->plugin) && !$plugin) {
|
if (isset($this->plugin) && !$plugin) {
|
||||||
$plugin = $this->plugin;
|
$plugin = $this->plugin;
|
||||||
|
@ -843,6 +846,7 @@ class View extends Object {
|
||||||
$name = $this->view;
|
$name = $this->view;
|
||||||
}
|
}
|
||||||
$name = str_replace('/', DS, $name);
|
$name = str_replace('/', DS, $name);
|
||||||
|
list($plugin, $name) = $this->_pluginSplit($name);
|
||||||
|
|
||||||
if (strpos($name, DS) === false && $name[0] !== '.') {
|
if (strpos($name, DS) === false && $name[0] !== '.') {
|
||||||
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
||||||
|
@ -858,8 +862,7 @@ class View extends Object {
|
||||||
$name = $this->viewPath . DS . $subDir . $name;
|
$name = $this->viewPath . DS . $subDir . $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$paths = $this->_paths($this->plugin);
|
$paths = $this->_paths($plugin);
|
||||||
|
|
||||||
$exts = $this->_getExtensions();
|
$exts = $this->_getExtensions();
|
||||||
foreach ($exts as $ext) {
|
foreach ($exts as $ext) {
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
|
@ -882,6 +885,31 @@ class View extends Object {
|
||||||
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
|
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _path($name, $plugin) {
|
||||||
|
$paths = $this->_paths($plugin);
|
||||||
|
$exts = $this->_getExtensions();
|
||||||
|
foreach ($exts as $ext) {
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
if (file_exists($path . $name . $ext)) {
|
||||||
|
return $path . $name . $ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _pluginSplit($name) {
|
||||||
|
$plugin = null;
|
||||||
|
list($first, $second) = pluginSplit($name);
|
||||||
|
if (CakePlugin::loaded($first) === true) {
|
||||||
|
$name = $second;
|
||||||
|
$plugin = $first;
|
||||||
|
}
|
||||||
|
if (isset($this->plugin) && !$plugin) {
|
||||||
|
$plugin = $this->plugin;
|
||||||
|
}
|
||||||
|
return array($plugin, $name);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns layout filename for this template as a string.
|
* Returns layout filename for this template as a string.
|
||||||
*
|
*
|
||||||
|
@ -898,7 +926,8 @@ class View extends Object {
|
||||||
if (!is_null($this->layoutPath)) {
|
if (!is_null($this->layoutPath)) {
|
||||||
$subDir = $this->layoutPath . DS;
|
$subDir = $this->layoutPath . DS;
|
||||||
}
|
}
|
||||||
$paths = $this->_paths($this->plugin);
|
list($plugin, $name) = $this->_pluginSplit($name);
|
||||||
|
$paths = $this->_paths($plugin);
|
||||||
$file = 'Layouts' . DS . $subDir . $name;
|
$file = 'Layouts' . DS . $subDir . $name;
|
||||||
|
|
||||||
$exts = $this->_getExtensions();
|
$exts = $this->_getExtensions();
|
||||||
|
|
Loading…
Add table
Reference in a new issue