From 40269cb6e2bbec19c89c517b1b05c44fe2d8d5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20G=C3=A1bor?= Date: Tue, 29 Mar 2016 14:55:25 +0200 Subject: [PATCH] Clean up --- modules/cms/classes/CmsCompoundObject.php | 4 +- modules/cms/classes/CmsException.php | 6 +-- modules/cms/controllers/Index.php | 2 +- modules/cms/twig/DebugExtension.php | 10 ++-- modules/cms/twig/FlashTokenParser.php | 4 +- modules/cms/widgets/AssetList.php | 6 +-- modules/cms/widgets/ComponentList.php | 6 ++- modules/cms/widgets/TemplateList.php | 51 +++---------------- .../widgets/templatelist/partials/_items.htm | 2 +- 9 files changed, 27 insertions(+), 64 deletions(-) diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 2d1d6cc24..abf381125 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -433,7 +433,7 @@ class CmsCompoundObject extends CmsObject * Determine if an attribute exists on the object. * * @param string $key - * @return void + * @return bool */ public function __isset($key) { @@ -459,7 +459,7 @@ class CmsCompoundObject extends CmsObject { if (in_array($method, $this->passthru)) { $collection = $this->get(); - return call_user_func_array(array($collection, $method), $parameters); + return call_user_func_array([$collection, $method], $parameters); } return parent::__call($method, $parameters); diff --git a/modules/cms/classes/CmsException.php b/modules/cms/classes/CmsException.php index e8d415b3f..ded3dc01b 100644 --- a/modules/cms/classes/CmsException.php +++ b/modules/cms/classes/CmsException.php @@ -17,19 +17,19 @@ use Exception; class CmsException extends ApplicationException { /** - * @var Cms\Classes\CmsCompoundObject A reference to a CMS object used for masking errors. + * @var \Cms\Classes\CmsCompoundObject A reference to a CMS object used for masking errors. */ protected $compoundObject; /** * @var array Collection of error codes for each error distinction. */ - protected static $errorCodes = array( + protected static $errorCodes = [ 100 => 'General', 200 => 'INI Settings', 300 => 'PHP Content', 400 => 'Twig Template' - ); + ]; /** * Creates the CMS exception object. diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index fa6063e3d..264473f67 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -343,7 +343,7 @@ class Index extends Controller { $class = $this->resolveTypeClassName($type); - if (!($template = call_user_func(array($class, 'load'), $this->theme, $path))) { + if (!($template = call_user_func([$class, 'load'], $this->theme, $path))) { throw new ApplicationException(trans('cms::lang.template.not_found')); } diff --git a/modules/cms/twig/DebugExtension.php b/modules/cms/twig/DebugExtension.php index c49f1ca27..80a4759dc 100644 --- a/modules/cms/twig/DebugExtension.php +++ b/modules/cms/twig/DebugExtension.php @@ -62,13 +62,13 @@ class DebugExtension extends Twig_Extension */ public function getFunctions() { - return array( - new Twig_SimpleFunction('dump', [$this, 'runDump'], array( + return [ + new Twig_SimpleFunction('dump', [$this, 'runDump'], [ 'is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true - )), - ); + ]), + ]; } /** @@ -141,7 +141,7 @@ class DebugExtension extends Twig_Extension /** * Dump information about a variable * - * @param mixed $variable Variable to dump + * @param mixed $variables Variable to dump * @param mixed $caption Caption [and subcaption] of the dump * @return void */ diff --git a/modules/cms/twig/FlashTokenParser.php b/modules/cms/twig/FlashTokenParser.php index bd3b439d4..ced972b5e 100644 --- a/modules/cms/twig/FlashTokenParser.php +++ b/modules/cms/twig/FlashTokenParser.php @@ -33,7 +33,7 @@ class FlashTokenParser extends Twig_TokenParser } $stream->expect(Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideIfEnd'), true); + $body = $this->parser->subparse([$this, 'decideIfEnd'], true); $stream->expect(Twig_Token::BLOCK_END_TYPE); return new FlashNode($name, $body, $lineno, $this->getTag()); @@ -41,7 +41,7 @@ class FlashTokenParser extends Twig_TokenParser public function decideIfEnd(Twig_Token $token) { - return $token->test(array('endflash')); + return $token->test(['endflash']); } /** diff --git a/modules/cms/widgets/AssetList.php b/modules/cms/widgets/AssetList.php index f2a1a327f..5ab05e998 100644 --- a/modules/cms/widgets/AssetList.php +++ b/modules/cms/widgets/AssetList.php @@ -76,7 +76,7 @@ class AssetList extends WidgetBase public function render() { return $this->makePartial('body', [ - 'data'=>$this->getData() + 'data' => $this->getData() ]); } @@ -108,14 +108,14 @@ class AssetList extends WidgetBase $this->putSession('currentPath', $path); return [ - '#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) + '#'.$this->getId('asset-list') => $this->makePartial('items', ['items' => $this->getData()]) ]; } public function onRefresh() { return [ - '#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) + '#'.$this->getId('asset-list') => $this->makePartial('items', ['items' => $this->getData()]) ]; } diff --git a/modules/cms/widgets/ComponentList.php b/modules/cms/widgets/ComponentList.php index 6abffbd0b..1ef0f9e7e 100644 --- a/modules/cms/widgets/ComponentList.php +++ b/modules/cms/widgets/ComponentList.php @@ -195,7 +195,7 @@ class ComponentList extends WidgetBase protected function getPluginComponents($plugin) { - $result = array(); + $result = []; $pluginClass = get_class($plugin); foreach ($this->pluginComponentList as $componentInfo) { if ($componentInfo->pluginClass == $pluginClass) { @@ -219,7 +219,9 @@ class ComponentList extends WidgetBase protected function updateList() { - return ['#'.$this->getId('component-list') => $this->makePartial('items', ['items'=>$this->getData()])]; + return ['#'.$this->getId('component-list') => $this->makePartial('items', [ + 'items' => $this->getData()] + )]; } protected function itemMatchesSearch(&$words, $item) diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index 5322689d9..16ba076c2 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -17,6 +17,8 @@ use Backend\Classes\WidgetBase; */ class TemplateList extends WidgetBase { + use \Backend\Traits\SelectableWidget; + protected $searchTerm = false; protected $dataSource; @@ -25,8 +27,6 @@ class TemplateList extends WidgetBase protected $groupStatusCache = false; - protected $selectedTemplatesCache = false; - /** * @var string object property to use as a title. */ @@ -78,6 +78,7 @@ class TemplateList extends WidgetBase $this->alias = $alias; $this->dataSource = $dataSource; $this->theme = Theme::getEditTheme(); + $this->selectionInputName = 'template'; parent::__construct($controller, []); @@ -129,11 +130,6 @@ class TemplateList extends WidgetBase $this->setGroupStatus(Input::get('group'), Input::get('status')); } - public function onSelect() - { - $this->extendSelection(); - } - public function onUpdate() { $this->extendSelection(); @@ -305,7 +301,9 @@ class TemplateList extends WidgetBase protected function updateList() { - return ['#'.$this->getId('template-list') => $this->makePartial('items', ['items'=>$this->getData()])]; + return [ + '#'.$this->getId('template-list') => $this->makePartial('items', ['items' => $this->getData()]) + ]; } protected function itemMatchesSearch($words, $item) @@ -387,41 +385,4 @@ class TemplateList extends WidgetBase $this->groupStatusCache = $statuses; $this->putSession($this->getThemeSessionKey('groups'), $statuses); } - - protected function getSelectedTemplates() - { - if ($this->selectedTemplatesCache !== false) { - return $this->selectedTemplatesCache; - } - - $templates = $this->getSession($this->getThemeSessionKey('selected'), []); - if (!is_array($templates)) { - return $this->selectedTemplatesCache = []; - } - - return $this->selectedTemplatesCache = $templates; - } - - protected function extendSelection() - { - $items = Input::get('template', []); - $currentSelection = $this->getSelectedTemplates(); - - $this->putSession($this->getThemeSessionKey('selected'), array_merge($currentSelection, $items)); - } - - protected function resetSelection() - { - $this->putSession($this->getThemeSessionKey('selected'), []); - } - - protected function isTemplateSelected($item) - { - $selectedTemplates = $this->getSelectedTemplates(); - if (!is_array($selectedTemplates) || !isset($selectedTemplates[$item->fileName])) { - return false; - } - - return $selectedTemplates[$item->fileName]; - } } diff --git a/modules/cms/widgets/templatelist/partials/_items.htm b/modules/cms/widgets/templatelist/partials/_items.htm index d7b15c31a..ebdcd27fc 100644 --- a/modules/cms/widgets/templatelist/partials/_items.htm +++ b/modules/cms/widgets/templatelist/partials/_items.htm @@ -34,7 +34,7 @@ id="" type="checkbox" name="template[fileName) ?>]" - isTemplateSelected($item) ? 'checked' : null ?> + isItemSelected($item->fileName) ? 'checked' : null ?> data-request="getEventHandler('onSelect') ?>" value="1">