Skip to content

Commit

Permalink
Remove Helper::$theme/$plugin.
Browse files Browse the repository at this point in the history
They can be got/set from view instance instead.
  • Loading branch information
ADmad committed Jun 8, 2018
1 parent a03a6ae commit 754559d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
59 changes: 43 additions & 16 deletions src/View/Helper.php
Expand Up @@ -64,27 +64,13 @@ class Helper implements EventListenerInterface
*/
protected $_helperMap = [];

/**
* The current theme name if any.
*
* @var string
*/
public $theme;

/**
* Request object
*
* @var \Cake\Http\ServerRequest
*/
public $request;

/**
* Plugin path
*
* @var string
*/
public $plugin;

/**
* Holds the fields ['field_name' => ['type' => 'string', 'length' => 100]],
* primaryKey and validates ['field_name']
Expand Down Expand Up @@ -153,6 +139,49 @@ public function __get($name)

return $this->{$name};
}

$removed = [
'theme' => 'getTheme',
'plugin' => 'getPlugin',
];
if (isset($removed[$name])) {
$method = $removed[$name];
deprecationWarning(sprintf(
'Helper::$%s is deprecated. Use $view->%s() instead.',
$name,
$method
));

return $this->_View->{$method}();
}
}

/**
* Magic setter for removed properties.
*
* @param string $name Property name.
* @param mixed $value Value to set.
* @return void
*/
public function __set($name, $value)
{
$removed = [
'template' => 'setTemplate',
'plugin' => 'setPlugin',
];
if (isset($removed[$name])) {
$method = $removed[$name];
deprecationWarning(sprintf(
'Helper::$%s is deprecated. Use $view->%s() instead.',
$name,
$method
));
$this->_View->{$method}($value);

return;
}

$this->{$name} = $value;
}

/**
Expand Down Expand Up @@ -273,8 +302,6 @@ public function __debugInfo()
{
return [
'helpers' => $this->helpers,
'theme' => $this->theme,
'plugin' => $this->plugin,
'fieldset' => $this->fieldset,
'tags' => $this->tags,
'implementedEvents' => $this->implementedEvents(),
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -544,7 +544,7 @@ protected function _formUrl($context, $options)
}

$actionDefaults = [
'plugin' => $this->plugin,
'plugin' => $this->_View->getPlugin(),
'controller' => $this->request->getParam('controller'),
'action' => $this->request->getParam('action'),
];
Expand Down
3 changes: 0 additions & 3 deletions src/View/HelperRegistry.php
Expand Up @@ -145,9 +145,6 @@ protected function _create($class, $alias, $settings)
{
$instance = new $class($this->_View, $settings);

$instance->theme = $this->_View->getTheme();
$instance->plugin = $this->_View->getRequest()->getParam('Plugin');

$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable) {
$this->getEventManager()->on($instance);
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase/View/HelperTest.php
Expand Up @@ -174,8 +174,6 @@ public function testDebugInfo()
'Html',
'TestPlugin.OtherHelper'
],
'theme' => null,
'plugin' => null,
'fieldset' => [],
'tags' => [],
'implementedEvents' => [
Expand Down

0 comments on commit 754559d

Please sign in to comment.