Skip to content

Commit 5e4abbe

Browse files
committed
Cleanup deprecated code.
1 parent 2ae1fd9 commit 5e4abbe

File tree

2 files changed

+12
-115
lines changed

2 files changed

+12
-115
lines changed

src/View/View.php

Lines changed: 9 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
* and then inserted into the selected layout. This also means you can pass data from the view to the
4141
* layout using `$this->set()`
4242
*
43-
* Since 2.1, the base View class also includes support for themes by default. Theme views are regular
44-
* view files that can provide unique HTML and static assets. If theme views are not found for the
45-
* current view the default app view files will be used. You can set `$this->theme = 'Mytheme'`
46-
* in your Controller to use the Themes.
47-
*
48-
* Example of theme path with `$this->theme = 'SuperHot';` Would be `Plugin/SuperHot/Template/Posts`
43+
* View class supports using plugins as themes. You can set
44+
* `$this->theme = 'SuperHot'` in your Controller to use plugin `SuperHot` as a
45+
* theme. Eg. If current action is Posts::index() then View class will look for
46+
* template file `plugins/SuperHot/Template/Posts/index.ctp`. If a theme template
47+
* is not found for the current action the default app template file is used.
4948
*
5049
* @property \Cake\View\Helper\CacheHelper $Cache
5150
* @property \Cake\View\Helper\FormHelper $Form
@@ -69,21 +68,20 @@ class View {
6968
/**
7069
* Helpers collection
7170
*
72-
* @var Cake\View\HelperRegistry
71+
* @var \Cake\View\HelperRegistry
7372
*/
7473
protected $_helpers;
7574

7675
/**
7776
* ViewBlock instance.
7877
*
79-
* @var ViewBlock
78+
* @var \Cake\View\ViewBlock
8079
*/
8180
public $Blocks;
8281

8382
/**
8483
* The name of the plugin.
8584
*
86-
* @link http://manual.cakephp.org/chapter/plugins
8785
* @var string
8886
*/
8987
public $plugin = null;
@@ -251,13 +249,6 @@ class View {
251249
'layoutPath', 'viewPath', 'plugin', 'passedArgs', 'cacheAction'
252250
);
253251

254-
/**
255-
* Scripts (and/or other <head /> tags) for the layout.
256-
*
257-
* @var array
258-
*/
259-
protected $_scripts = array();
260-
261252
/**
262253
* Holds an array of paths.
263254
*
@@ -465,21 +456,6 @@ public function render($view = null, $layout = null) {
465456
* Renders a layout. Returns output from _render(). Returns false on error.
466457
* Several variables are created for use in layout.
467458
*
468-
* - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
469-
* - `content_for_layout` - contains rendered view file
470-
* - `scripts_for_layout` - Contains content added with addScript() as well as any content in
471-
* the 'meta', 'css', and 'script' blocks. They are appended in that order.
472-
*
473-
* Deprecated features:
474-
*
475-
* - `$scripts_for_layout` is deprecated and will be removed in CakePHP 3.0.
476-
* Use the block features instead. `meta`, `css` and `script` will be populated
477-
* by the matching methods on HtmlHelper.
478-
* - `$title_for_layout` is deprecated and will be removed in CakePHP 3.0.
479-
* Use the `title` block instead.
480-
* - `$content_for_layout` is deprecated and will be removed in CakePHP 3.0.
481-
* Use the `content` block instead.
482-
*
483459
* @param string $content Content to render in a view, wrapped by the surrounding layout.
484460
* @param string $layout Layout name
485461
* @return mixed Rendered output, or false on error
@@ -498,24 +474,11 @@ public function renderLayout($content, $layout = null) {
498474
}
499475
$this->eventManager()->dispatch(new Event('View.beforeLayout', $this, array($layoutFileName)));
500476

501-
$scripts = implode("\n\t", $this->_scripts);
502-
$scripts .= $this->Blocks->get('meta') . $this->Blocks->get('css') . $this->Blocks->get('script');
503-
504-
$this->viewVars = array_merge($this->viewVars, array(
505-
'content_for_layout' => $content,
506-
'scripts_for_layout' => $scripts,
507-
));
508-
509477
$title = $this->Blocks->get('title');
510478
if ($title === '') {
511-
if (isset($this->viewVars['title_for_layout'])) {
512-
$title = $this->viewVars['title_for_layout'];
513-
} else {
514-
$title = Inflector::humanize($this->viewPath);
515-
}
479+
$title = Inflector::humanize($this->viewPath);
480+
$this->Blocks->set('title', $title);
516481
}
517-
$this->viewVars['title_for_layout'] = $title;
518-
$this->Blocks->set('title', $title);
519482

520483
$this->_currentType = static::TYPE_LAYOUT;
521484
$this->Blocks->set('content', $this->_render($layoutFileName));
@@ -564,17 +527,6 @@ public function getVars() {
564527
return array_keys($this->viewVars);
565528
}
566529

567-
/**
568-
* Returns the contents of the given View variable(s)
569-
*
570-
* @param string $var The view var you want the contents of.
571-
* @return mixed The content of the named var if its set, otherwise null.
572-
* @deprecated Will be removed in 3.0. Use View::get() instead.
573-
*/
574-
public function getVar($var) {
575-
return $this->get($var);
576-
}
577-
578530
/**
579531
* Returns the contents of the given View variable.
580532
*
@@ -765,30 +717,6 @@ public function __get($name) {
765717
return $this->{$name};
766718
}
767719

768-
/**
769-
* Magic accessor for deprecated attributes.
770-
*
771-
* @param string $name Name of the attribute to set.
772-
* @param mixed $value Value of the attribute to set.
773-
* @return void
774-
*/
775-
public function __set($name, $value) {
776-
$this->{$name} = $value;
777-
}
778-
779-
/**
780-
* Magic isset check for deprecated attributes.
781-
*
782-
* @param string $name Name of the attribute to check.
783-
* @return bool
784-
*/
785-
public function __isset($name) {
786-
if (isset($this->{$name})) {
787-
return true;
788-
}
789-
return false;
790-
}
791-
792720
/**
793721
* Interact with the HelperRegistry to load all the helpers.
794722
*

tests/TestCase/View/ViewTest.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,6 @@ public function index() {
9494

9595
}
9696

97-
/**
98-
* TestThemeView class
99-
*
100-
*/
101-
class TestThemeView extends View {
102-
103-
/**
104-
* getViewFileName method
105-
*
106-
* @param string $name Controller action to find template filename for
107-
* @return string Template filename
108-
*/
109-
public function getViewFileName($name = null) {
110-
return $this->_getViewFileName($name);
111-
}
112-
113-
/**
114-
* getLayoutFileName method
115-
*
116-
* @param string $name The name of the layout to find.
117-
* @return string Filename for layout file (.ctp).
118-
*/
119-
public function getLayoutFileName($name = null) {
120-
return $this->_getLayoutFileName($name);
121-
}
122-
123-
}
124-
12597
/**
12698
* TestView class
12799
*
@@ -360,7 +332,7 @@ public function testGetTemplate() {
360332
$request->action = 'display';
361333
$request->params['pass'] = array('home');
362334

363-
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
335+
$ThemeView = new TestView(null, null, null, $viewOptions);
364336
$ThemeView->theme = 'TestTheme';
365337
$expected = TEST_APP . 'TestApp' . DS . 'Template' . DS . 'Pages' . DS . 'home.ctp';
366338
$result = $ThemeView->getViewFileName('home');
@@ -384,7 +356,7 @@ public function testGetTemplate() {
384356
$result = $ThemeView->getLayoutFileName();
385357
$this->assertPathEquals($expected, $result);
386358

387-
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
359+
$ThemeView = new TestView(null, null, null, $viewOptions);
388360

389361
$ThemeView->theme = 'Company/TestPluginThree';
390362
$expected = Plugin::path('Company/TestPluginThree') . 'src' . DS . 'Template' . DS . 'Layout' . DS . 'default.ctp';
@@ -428,7 +400,7 @@ public function testPluginThemedGetTemplate() {
428400
'theme' => 'TestTheme'
429401
];
430402

431-
$ThemeView = new TestThemeView(null, null, null, $viewOptions);
403+
$ThemeView = new TestView(null, null, null, $viewOptions);
432404
$themePath = Plugin::path('TestTheme') . 'src' . DS . 'Template' . DS;
433405

434406
$expected = $themePath . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS . 'index.ctp';
@@ -1044,9 +1016,6 @@ public function testRender() {
10441016
$this->assertRegExp("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
10451017
$this->assertRegExp("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
10461018

1047-
$this->assertTrue(isset($View->viewVars['content_for_layout']), 'content_for_layout should be a view var');
1048-
$this->assertTrue(isset($View->viewVars['scripts_for_layout']), 'scripts_for_layout should be a view var');
1049-
10501019
$View = $this->PostsController->createView('Cake\Test\TestCase\View\TestView');
10511020
$result = $View->render(false, 'ajax2');
10521021

0 commit comments

Comments
 (0)