This commit is contained in:
Pásztor Gábor 2016-03-29 14:55:25 +02:00
parent 5a9d62d54a
commit 40269cb6e2
9 changed files with 27 additions and 64 deletions

View File

@ -433,7 +433,7 @@ class CmsCompoundObject extends CmsObject
* Determine if an attribute exists on the object. * Determine if an attribute exists on the object.
* *
* @param string $key * @param string $key
* @return void * @return bool
*/ */
public function __isset($key) public function __isset($key)
{ {
@ -459,7 +459,7 @@ class CmsCompoundObject extends CmsObject
{ {
if (in_array($method, $this->passthru)) { if (in_array($method, $this->passthru)) {
$collection = $this->get(); $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); return parent::__call($method, $parameters);

View File

@ -17,19 +17,19 @@ use Exception;
class CmsException extends ApplicationException 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; protected $compoundObject;
/** /**
* @var array Collection of error codes for each error distinction. * @var array Collection of error codes for each error distinction.
*/ */
protected static $errorCodes = array( protected static $errorCodes = [
100 => 'General', 100 => 'General',
200 => 'INI Settings', 200 => 'INI Settings',
300 => 'PHP Content', 300 => 'PHP Content',
400 => 'Twig Template' 400 => 'Twig Template'
); ];
/** /**
* Creates the CMS exception object. * Creates the CMS exception object.

View File

@ -343,7 +343,7 @@ class Index extends Controller
{ {
$class = $this->resolveTypeClassName($type); $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')); throw new ApplicationException(trans('cms::lang.template.not_found'));
} }

View File

@ -62,13 +62,13 @@ class DebugExtension extends Twig_Extension
*/ */
public function getFunctions() public function getFunctions()
{ {
return array( return [
new Twig_SimpleFunction('dump', [$this, 'runDump'], array( new Twig_SimpleFunction('dump', [$this, 'runDump'], [
'is_safe' => ['html'], 'is_safe' => ['html'],
'needs_context' => true, 'needs_context' => true,
'needs_environment' => true 'needs_environment' => true
)), ]),
); ];
} }
/** /**
@ -141,7 +141,7 @@ class DebugExtension extends Twig_Extension
/** /**
* Dump information about a variable * 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 * @param mixed $caption Caption [and subcaption] of the dump
* @return void * @return void
*/ */

View File

@ -33,7 +33,7 @@ class FlashTokenParser extends Twig_TokenParser
} }
$stream->expect(Twig_Token::BLOCK_END_TYPE); $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); $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new FlashNode($name, $body, $lineno, $this->getTag()); return new FlashNode($name, $body, $lineno, $this->getTag());
@ -41,7 +41,7 @@ class FlashTokenParser extends Twig_TokenParser
public function decideIfEnd(Twig_Token $token) public function decideIfEnd(Twig_Token $token)
{ {
return $token->test(array('endflash')); return $token->test(['endflash']);
} }
/** /**

View File

@ -76,7 +76,7 @@ class AssetList extends WidgetBase
public function render() public function render()
{ {
return $this->makePartial('body', [ return $this->makePartial('body', [
'data'=>$this->getData() 'data' => $this->getData()
]); ]);
} }
@ -108,14 +108,14 @@ class AssetList extends WidgetBase
$this->putSession('currentPath', $path); $this->putSession('currentPath', $path);
return [ return [
'#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) '#'.$this->getId('asset-list') => $this->makePartial('items', ['items' => $this->getData()])
]; ];
} }
public function onRefresh() public function onRefresh()
{ {
return [ return [
'#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) '#'.$this->getId('asset-list') => $this->makePartial('items', ['items' => $this->getData()])
]; ];
} }

View File

@ -195,7 +195,7 @@ class ComponentList extends WidgetBase
protected function getPluginComponents($plugin) protected function getPluginComponents($plugin)
{ {
$result = array(); $result = [];
$pluginClass = get_class($plugin); $pluginClass = get_class($plugin);
foreach ($this->pluginComponentList as $componentInfo) { foreach ($this->pluginComponentList as $componentInfo) {
if ($componentInfo->pluginClass == $pluginClass) { if ($componentInfo->pluginClass == $pluginClass) {
@ -219,7 +219,9 @@ class ComponentList extends WidgetBase
protected function updateList() 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) protected function itemMatchesSearch(&$words, $item)

View File

@ -17,6 +17,8 @@ use Backend\Classes\WidgetBase;
*/ */
class TemplateList extends WidgetBase class TemplateList extends WidgetBase
{ {
use \Backend\Traits\SelectableWidget;
protected $searchTerm = false; protected $searchTerm = false;
protected $dataSource; protected $dataSource;
@ -25,8 +27,6 @@ class TemplateList extends WidgetBase
protected $groupStatusCache = false; protected $groupStatusCache = false;
protected $selectedTemplatesCache = false;
/** /**
* @var string object property to use as a title. * @var string object property to use as a title.
*/ */
@ -78,6 +78,7 @@ class TemplateList extends WidgetBase
$this->alias = $alias; $this->alias = $alias;
$this->dataSource = $dataSource; $this->dataSource = $dataSource;
$this->theme = Theme::getEditTheme(); $this->theme = Theme::getEditTheme();
$this->selectionInputName = 'template';
parent::__construct($controller, []); parent::__construct($controller, []);
@ -129,11 +130,6 @@ class TemplateList extends WidgetBase
$this->setGroupStatus(Input::get('group'), Input::get('status')); $this->setGroupStatus(Input::get('group'), Input::get('status'));
} }
public function onSelect()
{
$this->extendSelection();
}
public function onUpdate() public function onUpdate()
{ {
$this->extendSelection(); $this->extendSelection();
@ -305,7 +301,9 @@ class TemplateList extends WidgetBase
protected function updateList() 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) protected function itemMatchesSearch($words, $item)
@ -387,41 +385,4 @@ class TemplateList extends WidgetBase
$this->groupStatusCache = $statuses; $this->groupStatusCache = $statuses;
$this->putSession($this->getThemeSessionKey('groups'), $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];
}
} }

View File

@ -34,7 +34,7 @@
id="<?= $cbId ?>" id="<?= $cbId ?>"
type="checkbox" type="checkbox"
name="template[<?= e($item->fileName) ?>]" name="template[<?= e($item->fileName) ?>]"
<?= $this->isTemplateSelected($item) ? 'checked' : null ?> <?= $this->isItemSelected($item->fileName) ? 'checked' : null ?>
data-request="<?= $this->getEventHandler('onSelect') ?>" data-request="<?= $this->getEventHandler('onSelect') ?>"
value="1"> value="1">
<label for="<?= $cbId ?>">Select</label> <label for="<?= $cbId ?>">Select</label>