Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clean up internal API's
- There was some duplication in element() for handing plugins.
- Deprecate options[plugin] for element()
- Add file omitted in previous commit.
  • Loading branch information
markstory committed Dec 28, 2011
1 parent d8cbe8a commit 047e93e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Test/test_app/View/Pages/page.home.ctp
@@ -0,0 +1,2 @@
Empty page with a dot in the filename.
Used to test plugin.view and missing plugins.
27 changes: 16 additions & 11 deletions lib/Cake/View/View.php
Expand Up @@ -31,6 +31,7 @@
* and then inserted into the selected layout. This also means you can pass data from the view to the
* layout using `$this->set()`
*
*
* @package Cake.View
* @property CacheHelper $Cache
* @property FormHelper $Form
Expand Down Expand Up @@ -291,30 +292,29 @@ public function __construct($controller) {
* 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,
* or `MyPlugin.template` to use the template element from MyPlugin , will be overriden by $options['plugin']
* or `MyPlugin.template` to use the template element from MyPlugin. If the element
* is not found in the plugin, the normal view path cascade will be searched.
* @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:
* - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
* If an array, the following keys can be used:
* - `config` - Used to store the cached element in a custom cache configuration.
* - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
* - `plugin` - Load an element from a specific plugin.
* - `plugin` - Load an element from a specific plugin. This option is deprecated, see below.
* - `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element.
* Defaults to false.
* @return string Rendered Element
* @deprecated The `$options['plugin']` is deprecated and will be removed in CakePHP 3.0. Use
* `Plugin.element_name` instead.
*/
public function element($name, $data = array(), $options = array()) {
$file = $plugin = $key = null;
$callbacks = false;

if (isset($options['plugin'])) {
$plugin = Inflector::camelize($options['plugin']);
} else {
list($plugin, $name) = $this->_pluginSplit($name);
}
if (isset($this->plugin) && !$plugin) {
$plugin = $this->plugin;
$name = Inflector::camelize($options['plugin']) . '.' . $name;
}

if (isset($options['callbacks'])) {
$callbacks = $options['callbacks'];
}
Expand Down Expand Up @@ -343,7 +343,7 @@ public function element($name, $data = array(), $options = array()) {
}
}

$file = $this->_getElementFilename($name, $plugin);
$file = $this->_getElementFilename($name);

if ($file) {
if (!$this->_helpersLoaded) {
Expand Down Expand Up @@ -384,6 +384,10 @@ public function element($name, $data = array(), $options = array()) {
*
* If View::$autoRender is false and no `$layout` is provided, the view will be returned bare.
*
* View and layout names can point to plugin views/layouts. Using the `Plugin.view` syntax
* a plugin view/layout can be used instead of the app ones. If the chosen plugin is not found
* the view will be located along the regular view path cascade.
*
* @param string $view Name of view file to use
* @param string $layout Layout to use.
* @return string Rendered Element
Expand Down Expand Up @@ -955,10 +959,11 @@ protected function _getExtensions() {
* Finds an element filename, returns false on failure.
*
* @param string $name The name of the element to find.
* @param string $plugin The plugin name the element is in.
* @return mixed Either a string to the element filename or false when one can't be found.
*/
protected function _getElementFileName($name, $plugin = null) {
protected function _getElementFileName($name) {
list($plugin, $name) = $this->_pluginSplit($name);

$paths = $this->_paths($plugin);
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
Expand Down

0 comments on commit 047e93e

Please sign in to comment.