Updating backend/classes
This commit is contained in:
parent
b01d3e540f
commit
7dc24cfff1
|
|
@ -78,12 +78,12 @@ class AuthManager extends RainAuthManager
|
|||
* @param string $owner Specifies the menu items owner plugin or module in the format Vendor/Module.
|
||||
* @param array $definitions An array of the menu item definitions.
|
||||
*/
|
||||
public function registerPermissions($owner, array $definitions)
|
||||
public function registerPermissions($owner, array $definitions)
|
||||
{
|
||||
foreach ($definitions as $code=>$definition) {
|
||||
foreach ($definitions as $code => $definition) {
|
||||
$permission = (object)array_merge(self::$permissionDefaults, array_merge($definition, [
|
||||
'code'=>$code,
|
||||
'owner'=>$owner
|
||||
'code' => $code,
|
||||
'owner' => $owner
|
||||
]));
|
||||
|
||||
$this->permissions[] = $permission;
|
||||
|
|
@ -96,8 +96,9 @@ class AuthManager extends RainAuthManager
|
|||
*/
|
||||
public function listPermissions()
|
||||
{
|
||||
if ($this->permissionCache !== false)
|
||||
if ($this->permissionCache !== false) {
|
||||
return $this->permissionCache;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load module items
|
||||
|
|
@ -113,8 +114,9 @@ class AuthManager extends RainAuthManager
|
|||
|
||||
foreach ($plugins as $id => $plugin) {
|
||||
$items = $plugin->registerPermissions();
|
||||
if (!is_array($items))
|
||||
if (!is_array($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->registerPermissions($id, $items);
|
||||
}
|
||||
|
|
@ -122,14 +124,14 @@ class AuthManager extends RainAuthManager
|
|||
/*
|
||||
* Sort permission items
|
||||
*/
|
||||
usort($this->permissions, function($a, $b) {
|
||||
if ($a->order == $b->order)
|
||||
usort($this->permissions, function ($a, $b) {
|
||||
if ($a->order == $b->order) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $a->order > $b->order ? 1 : -1;
|
||||
});
|
||||
|
||||
return $this->permissionCache = $this->permissions;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ class BackendController extends ControllerBase
|
|||
self::$action = $action = isset($params[2]) ? $this->parseAction($params[2]) : 'index';
|
||||
self::$params = $controllerParams = array_slice($params, 3);
|
||||
$controllerClass = '\\'.$module.'\Controllers\\'.$controller;
|
||||
if ($controllerObj = $this->findController($controllerClass, $action, '/modules'))
|
||||
if ($controllerObj = $this->findController($controllerClass, $action, '/modules')) {
|
||||
return $controllerObj->run($action, $controllerParams);
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for a Plugin controller
|
||||
|
|
@ -58,8 +59,13 @@ class BackendController extends ControllerBase
|
|||
self::$action = $action = isset($params[3]) ? $this->parseAction($params[3]) : 'index';
|
||||
self::$params = $controllerParams = array_slice($params, 4);
|
||||
$controllerClass = '\\'.$author.'\\'.$plugin.'\Controllers\\'.$controller;
|
||||
if ($controllerObj = $this->findController($controllerClass, $action, Config::get('cms.pluginsDir', '/plugins')))
|
||||
if ($controllerObj = $this->findController(
|
||||
$controllerClass,
|
||||
$action,
|
||||
Config::get('cms.pluginsDir', '/plugins')
|
||||
)) {
|
||||
return $controllerObj->run($action, $controllerParams);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -83,17 +89,20 @@ class BackendController extends ControllerBase
|
|||
if (!class_exists($controller)) {
|
||||
$controller = Str::normalizeClassName($controller);
|
||||
$controllerFile = PATH_BASE.$dirPrefix.strtolower(str_replace('\\', '/', $controller)) . '.php';
|
||||
if ($controllerFile = File::existsInsensitive($controllerFile))
|
||||
if ($controllerFile = File::existsInsensitive($controllerFile)) {
|
||||
include_once($controllerFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($controller))
|
||||
if (!class_exists($controller)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$controllerObj = App::make($controller);
|
||||
|
||||
if ($controllerObj->actionExists($action))
|
||||
if ($controllerObj->actionExists($action)) {
|
||||
return $controllerObj;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -105,9 +114,10 @@ class BackendController extends ControllerBase
|
|||
*/
|
||||
protected function parseAction($actionName)
|
||||
{
|
||||
if (strpos($actionName, '-') !== false)
|
||||
if (strpos($actionName, '-') !== false) {
|
||||
return camel_case($actionName);
|
||||
}
|
||||
|
||||
return $actionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ class BackendHelper
|
|||
$backendUri = Config::get('cms.backendUri');
|
||||
$baseUrl = Request::getBaseUrl();
|
||||
|
||||
if ($path === null)
|
||||
if ($path === null) {
|
||||
return $baseUrl . '/' . $backendUri;
|
||||
}
|
||||
|
||||
$path = RouterHelper::normalizeUrl($path);
|
||||
return $baseUrl . '/' . $backendUri . $path;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,15 @@ class Controller extends Extendable
|
|||
/**
|
||||
* @var array Default methods which cannot be called as actions.
|
||||
*/
|
||||
public $hiddenActions = ['run', 'actionExists', 'pageAction', 'getId', 'setStatusCode', 'handleError', 'makeHintPartial'];
|
||||
public $hiddenActions = [
|
||||
'run',
|
||||
'actionExists',
|
||||
'pageAction',
|
||||
'getId',
|
||||
'setStatusCode',
|
||||
'handleError',
|
||||
'makeHintPartial'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array Controller specified methods which cannot be called as actions.
|
||||
|
|
@ -164,14 +172,16 @@ class Controller extends Extendable
|
|||
|
||||
// Not logged in, redirect to login screen or show ajax error
|
||||
if (!BackendAuth::check()) {
|
||||
return Request::ajax()
|
||||
return Request::ajax() {
|
||||
? Response::make(Lang::get('backend::lang.page.access_denied.label'), 403)
|
||||
: Redirect::guest(Backend::url('backend/auth'));
|
||||
}
|
||||
}
|
||||
|
||||
// Check his access groups against the page definition
|
||||
if ($this->requiredPermissions && !$this->user->hasAnyAccess($this->requiredPermissions))
|
||||
if ($this->requiredPermissions && !$this->user->hasAnyAccess($this->requiredPermissions)) {
|
||||
return Response::make(View::make('backend::access_denied'), 403);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -179,8 +189,7 @@ class Controller extends Extendable
|
|||
*/
|
||||
if (Session::has('locale')) {
|
||||
App::setLocale(Session::get('locale'));
|
||||
}
|
||||
elseif ($this->user && $locale = BackendPreferences::get('locale')) {
|
||||
} elseif ($this->user && $locale = BackendPreferences::get('locale')) {
|
||||
Session::put('locale', $locale);
|
||||
App::setLocale($locale);
|
||||
}
|
||||
|
|
@ -188,22 +197,29 @@ class Controller extends Extendable
|
|||
/*
|
||||
* Execute AJAX event
|
||||
*/
|
||||
if ($ajaxResponse = $this->execAjaxHandlers())
|
||||
if ($ajaxResponse = $this->execAjaxHandlers()) {
|
||||
return $ajaxResponse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute postback handler
|
||||
*/
|
||||
if (($handler = post('_handler')) && ($handlerResponse = $this->runAjaxHandler($handler)) && $handlerResponse !== true)
|
||||
if (
|
||||
($handler = post('_handler')) &&
|
||||
($handlerResponse = $this->runAjaxHandler($handler)) &&
|
||||
$handlerResponse !== true
|
||||
) {
|
||||
return $handlerResponse;
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute page action
|
||||
*/
|
||||
$result = $this->execPageAction($action, $params);
|
||||
|
||||
if (!is_string($result))
|
||||
if (!is_string($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return Response::make($result, $this->statusCode);
|
||||
}
|
||||
|
|
@ -218,12 +234,14 @@ class Controller extends Extendable
|
|||
*/
|
||||
public function actionExists($name, $internal = false)
|
||||
{
|
||||
if (!strlen($name) || substr($name, 0, 1) == '_' || !$this->methodExists($name))
|
||||
if (!strlen($name) || substr($name, 0, 1) == '_' || !$this->methodExists($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->hiddenActions as $method) {
|
||||
if (strtolower($name) == strtolower($method))
|
||||
if (strtolower($name) == strtolower($method)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ownMethod = method_exists($this, $name);
|
||||
|
|
@ -231,15 +249,18 @@ class Controller extends Extendable
|
|||
if ($ownMethod) {
|
||||
$methodInfo = new \ReflectionMethod($this, $name);
|
||||
$public = $methodInfo->isPublic();
|
||||
if ($public)
|
||||
if ($public) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($internal && (($ownMethod && $methodInfo->isProtected()) || !$ownMethod))
|
||||
if ($internal && (($ownMethod && $methodInfo->isProtected()) || !$ownMethod)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$ownMethod)
|
||||
if (!$ownMethod) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -250,8 +271,9 @@ class Controller extends Extendable
|
|||
*/
|
||||
public function pageAction()
|
||||
{
|
||||
if (!$this->action)
|
||||
if (!$this->action) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->suppressView = true;
|
||||
$this->execPageAction($this->action, $this->params);
|
||||
|
|
@ -267,14 +289,20 @@ class Controller extends Extendable
|
|||
{
|
||||
$result = null;
|
||||
|
||||
if (!$this->actionExists($actionName))
|
||||
throw new SystemException(sprintf("Action %s is not found in the controller %s", $actionName, get_class($this)));
|
||||
if (!$this->actionExists($actionName)) {
|
||||
throw new SystemException(sprintf(
|
||||
"Action %s is not found in the controller %s",
|
||||
$actionName,
|
||||
get_class($this)
|
||||
));
|
||||
}
|
||||
|
||||
// Execute the action
|
||||
$result = call_user_func_array([$this, $actionName], $parameters);
|
||||
|
||||
if ($result instanceof RedirectResponse)
|
||||
if ($result instanceof RedirectResponse) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Translate the page title
|
||||
$this->pageTitle = $this->pageTitle
|
||||
|
|
@ -282,8 +310,9 @@ class Controller extends Extendable
|
|||
: Lang::get('backend::lang.page.untitled');
|
||||
|
||||
// Load the view
|
||||
if (!$this->suppressView && is_null($result))
|
||||
if (!$this->suppressView && is_null($result)) {
|
||||
return $this->makeView($actionName);
|
||||
}
|
||||
|
||||
return $this->makeViewContent($result);
|
||||
}
|
||||
|
|
@ -299,8 +328,9 @@ class Controller extends Extendable
|
|||
/*
|
||||
* Validate the handler name
|
||||
*/
|
||||
if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler))
|
||||
if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) {
|
||||
throw new SystemException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler]));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate the handler partial list
|
||||
|
|
@ -310,11 +340,14 @@ class Controller extends Extendable
|
|||
|
||||
// @todo Do we need to validate backend partials?
|
||||
// foreach ($partialList as $partial) {
|
||||
// if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial))
|
||||
// throw new SystemException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial]));
|
||||
// if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) {
|
||||
// throw new SystemException(Lang::get(
|
||||
// 'cms::lang.partial.invalid_name',
|
||||
// ['name' => $partial]
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$partialList = [];
|
||||
}
|
||||
|
||||
|
|
@ -323,23 +356,26 @@ class Controller extends Extendable
|
|||
/*
|
||||
* Execute the handler
|
||||
*/
|
||||
if (!$result = $this->runAjaxHandler($handler))
|
||||
if (!$result = $this->runAjaxHandler($handler)) {
|
||||
throw new ApplicationException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler]));
|
||||
}
|
||||
|
||||
/*
|
||||
* If the handler returned an array, we should add it to output for rendering.
|
||||
* If it is a string, add it to the array with the key "result".
|
||||
*/
|
||||
if (is_array($result))
|
||||
if (is_array($result)) {
|
||||
$responseContents = array_merge($responseContents, $result);
|
||||
elseif (is_string($result))
|
||||
} elseif (is_string($result)) {
|
||||
$responseContents['result'] = $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Render partials and return the response as array that will be converted to JSON automatically.
|
||||
*/
|
||||
foreach ($partialList as $partial)
|
||||
foreach ($partialList as $partial) {
|
||||
$responseContents[$partial] = $this->makePartial($partial);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the handler returned a redirect, process it so framework.js knows to redirect
|
||||
|
|
@ -347,11 +383,10 @@ class Controller extends Extendable
|
|||
*/
|
||||
if ($result instanceof RedirectResponse) {
|
||||
$responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
|
||||
}
|
||||
/*
|
||||
* No redirect is used, look for any flash messages
|
||||
*/
|
||||
else if (Flash::check()) {
|
||||
} elseif (Flash::check()) {
|
||||
$responseContents['#layout-flash-messages'] = $this->makeLayoutPartial('flash_messages');
|
||||
}
|
||||
|
||||
|
|
@ -363,8 +398,7 @@ class Controller extends Extendable
|
|||
}
|
||||
|
||||
return Response::make()->setContent($responseContents);
|
||||
}
|
||||
catch (ValidationException $ex) {
|
||||
} catch (ValidationException $ex) {
|
||||
/*
|
||||
* Handle validation error gracefully
|
||||
*/
|
||||
|
|
@ -373,15 +407,18 @@ class Controller extends Extendable
|
|||
$responseContents['#layout-flash-messages'] = $this->makeLayoutPartial('flash_messages');
|
||||
$responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields();
|
||||
return Response::make($responseContents, 406);
|
||||
}
|
||||
catch (MassAssignmentException $ex) {
|
||||
return Response::make(Lang::get('backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()]), 500);
|
||||
}
|
||||
catch (ApplicationException $ex) {
|
||||
} catch (MassAssignmentException $ex) {
|
||||
return Response::make(
|
||||
Lang::get('backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()]),
|
||||
500
|
||||
);
|
||||
} catch (ApplicationException $ex) {
|
||||
return Response::make($ex->getMessage(), 500);
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
return Response::make(sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()), 500);
|
||||
} catch (Exception $ex) {
|
||||
return Response::make(
|
||||
sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()),
|
||||
500
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -406,20 +443,21 @@ class Controller extends Extendable
|
|||
*/
|
||||
$this->pageAction();
|
||||
|
||||
if ($this->fatalError)
|
||||
if ($this->fatalError) {
|
||||
throw new SystemException($this->fatalError);
|
||||
}
|
||||
|
||||
if (!isset($this->widget->{$widgetName}))
|
||||
if (!isset($this->widget->{$widgetName})) {
|
||||
throw new SystemException(Lang::get('backend::lang.widget.not_bound', ['name'=>$widgetName]));
|
||||
}
|
||||
|
||||
if (($widget = $this->widget->{$widgetName}) && method_exists($widget, $handlerName)) {
|
||||
$result = call_user_func_array([$widget, $handlerName], $this->params);
|
||||
return ($result) ?: true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/*
|
||||
* Process page specific handler (index_onSomething)
|
||||
* Process page specific handler (index_onSomething) {
|
||||
*/
|
||||
$pageHandler = $this->action . '_' . $handler;
|
||||
|
||||
|
|
@ -429,7 +467,7 @@ class Controller extends Extendable
|
|||
}
|
||||
|
||||
/*
|
||||
* Process page global handler (onSomething)
|
||||
* Process page global handler (onSomething) {
|
||||
*/
|
||||
if ($this->methodExists($handler)) {
|
||||
$result = call_user_func_array([$this, $handler], $this->params);
|
||||
|
|
@ -459,8 +497,9 @@ class Controller extends Extendable
|
|||
public function getId($suffix = null)
|
||||
{
|
||||
$id = class_basename(get_called_class()) . '-' . $this->action;
|
||||
if ($suffix !== null)
|
||||
if ($suffix !== null) {
|
||||
$id .= '-' . $suffix;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
|
@ -498,8 +537,9 @@ class Controller extends Extendable
|
|||
*/
|
||||
public function makeHintPartial($name, $partial = null, array $params = [])
|
||||
{
|
||||
if (!$partial)
|
||||
if (!$partial) {
|
||||
$partial = $name;
|
||||
}
|
||||
|
||||
return $this->makeLayoutPartial('hint', [
|
||||
'hintName' => $name,
|
||||
|
|
@ -515,8 +555,9 @@ class Controller extends Extendable
|
|||
*/
|
||||
public function onHideBackendHint()
|
||||
{
|
||||
if (!$name = post('name'))
|
||||
if (!$name = post('name')) {
|
||||
throw new ApplicationException('Missing a hint name.');
|
||||
}
|
||||
|
||||
$preferences = UserPreferences::forUser();
|
||||
$hiddenHints = $preferences->get('backend::hints.hidden', []);
|
||||
|
|
@ -535,5 +576,4 @@ class Controller extends Extendable
|
|||
$hiddenHints = UserPreferences::forUser()->get('backend::hints.hidden', []);
|
||||
return array_key_exists($name, $hiddenHints);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,10 @@ class ControllerBehavior extends ExtensionBase
|
|||
|
||||
// Option A: (@todo Determine which is faster by benchmark)
|
||||
// $relativePath = strtolower(str_replace('\\', '/', get_called_class()));
|
||||
// $this->viewPath = $this->configPath = ['modules/' . $relativePath . '/partials', 'plugins/' . $relativePath . '/partials'];
|
||||
// $this->viewPath = $this->configPath = [
|
||||
// 'modules/' . $relativePath . '/partials',
|
||||
// 'plugins/' . $relativePath . '/partials'
|
||||
// ];
|
||||
// $this->assetPath = ['modules/' . $relativePath . '/assets', 'plugins/' . $relativePath . '/assets'];
|
||||
|
||||
// Option B:
|
||||
|
|
@ -93,8 +96,9 @@ class ControllerBehavior extends ExtensionBase
|
|||
* First part will be the field name, pop it off
|
||||
*/
|
||||
$fieldName = array_shift($keyParts);
|
||||
if (!isset($this->config->{$fieldName}))
|
||||
if (!isset($this->config->{$fieldName})) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$result = $this->config->{$fieldName};
|
||||
|
||||
|
|
@ -102,8 +106,9 @@ class ControllerBehavior extends ExtensionBase
|
|||
* Loop the remaining key parts and build a result
|
||||
*/
|
||||
foreach ($keyParts as $key) {
|
||||
if (!array_key_exists($key, $result))
|
||||
if (!array_key_exists($key, $result)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$result = $result[$key];
|
||||
}
|
||||
|
|
@ -121,8 +126,9 @@ class ControllerBehavior extends ExtensionBase
|
|||
*/
|
||||
protected function hideAction($methodName)
|
||||
{
|
||||
if (!is_array($methodName))
|
||||
if (!is_array($methodName)) {
|
||||
$methodName = [$methodName];
|
||||
}
|
||||
|
||||
$this->controller->hiddenActions = array_merge($this->controller->hiddenActions, $methodName);
|
||||
}
|
||||
|
|
@ -148,4 +154,4 @@ class ControllerBehavior extends ExtensionBase
|
|||
{
|
||||
return method_exists($this->controller, $methodName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,18 +113,39 @@ class FilterScope
|
|||
*/
|
||||
protected function evalConfig($config)
|
||||
{
|
||||
if (isset($config['options'])) $this->options($config['options']);
|
||||
if (isset($config['context'])) $this->context = $config['context'];
|
||||
if (isset($config['default'])) $this->defaults = $config['default'];
|
||||
if (isset($config['conditions'])) $this->conditions = $config['conditions'];
|
||||
if (isset($config['scope'])) $this->scope = $config['scope'];
|
||||
if (isset($config['cssClass'])) $this->cssClass = $config['cssClass'];
|
||||
if (isset($config['nameFrom'])) $this->nameFrom = $config['nameFrom'];
|
||||
if (isset($config['descriptionFrom'])) $this->descriptionFrom = $config['descriptionFrom'];
|
||||
if (isset($config['options'])) {
|
||||
$this->options($config['options']);
|
||||
}
|
||||
if (isset($config['context'])) {
|
||||
$this->context = $config['context'];
|
||||
}
|
||||
if (isset($config['default'])) {
|
||||
$this->defaults = $config['default'];
|
||||
}
|
||||
if (isset($config['conditions'])) {
|
||||
$this->conditions = $config['conditions'];
|
||||
}
|
||||
if (isset($config['scope'])) {
|
||||
$this->scope = $config['scope'];
|
||||
}
|
||||
if (isset($config['cssClass'])) {
|
||||
$this->cssClass = $config['cssClass'];
|
||||
}
|
||||
if (isset($config['nameFrom'])) {
|
||||
$this->nameFrom = $config['nameFrom'];
|
||||
}
|
||||
if (isset($config['descriptionFrom'])) {
|
||||
$this->descriptionFrom = $config['descriptionFrom'];
|
||||
}
|
||||
|
||||
/* @todo Remove line if year >= 2015 */ if (isset($config['nameColumn'])) $this->nameFrom = $config['nameColumn'];
|
||||
// @todo Remove line if year >= 2015
|
||||
if (isset($config['nameColumn'])) {
|
||||
$this->nameFrom = $config['nameColumn'];
|
||||
}
|
||||
|
||||
if (array_key_exists('disabled', $config)) $this->disabled = $config['disabled'];
|
||||
if (array_key_exists('disabled', $config)) {
|
||||
$this->disabled = $config['disabled'];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
|
@ -136,13 +157,14 @@ class FilterScope
|
|||
$id = 'scope';
|
||||
$id .= '-'.$this->scopeName;
|
||||
|
||||
if ($suffix)
|
||||
if ($suffix) {
|
||||
$id .= '-'.$suffix;
|
||||
}
|
||||
|
||||
if ($this->idPrefix)
|
||||
if ($this->idPrefix) {
|
||||
$id = $this->idPrefix . '-' . $id;
|
||||
}
|
||||
|
||||
return Str::evalHtmlId($id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,15 +193,13 @@ class FormField
|
|||
if ($value === null) {
|
||||
if (is_array($this->options)) {
|
||||
return $this->options;
|
||||
}
|
||||
elseif (is_callable($this->options)) {
|
||||
} elseif (is_callable($this->options)) {
|
||||
$callable = $this->options;
|
||||
return $callable();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->options = $value;
|
||||
}
|
||||
|
||||
|
|
@ -233,28 +231,67 @@ class FormField
|
|||
*/
|
||||
protected function evalConfig($config)
|
||||
{
|
||||
if (isset($config['options'])) $this->options($config['options']);
|
||||
if (isset($config['span'])) $this->span($config['span']);
|
||||
if (isset($config['context'])) $this->context = $config['context'];
|
||||
if (isset($config['size'])) $this->size($config['size']);
|
||||
if (isset($config['tab'])) $this->tab($config['tab']);
|
||||
if (isset($config['commentAbove'])) $this->comment($config['commentAbove'], 'above');
|
||||
if (isset($config['comment'])) $this->comment($config['comment']);
|
||||
if (isset($config['placeholder'])) $this->placeholder = $config['placeholder'];
|
||||
if (isset($config['default'])) $this->defaults = $config['default'];
|
||||
if (isset($config['cssClass'])) $this->cssClass = $config['cssClass'];
|
||||
if (isset($config['attributes'])) $this->attributes($config['attributes']);
|
||||
if (isset($config['containerAttributes'])) $this->attributes($config['containerAttributes'], 'container');
|
||||
if (isset($config['depends'])) $this->depends = $config['depends'];
|
||||
if (isset($config['path'])) $this->path = $config['path'];
|
||||
if (isset($config['options'])) {
|
||||
$this->options($config['options']);
|
||||
}
|
||||
if (isset($config['span'])) {
|
||||
$this->span($config['span']);
|
||||
}
|
||||
if (isset($config['context'])) {
|
||||
$this->context = $config['context'];
|
||||
}
|
||||
if (isset($config['size'])) {
|
||||
$this->size($config['size']);
|
||||
}
|
||||
if (isset($config['tab'])) {
|
||||
$this->tab($config['tab']);
|
||||
}
|
||||
if (isset($config['commentAbove'])) {
|
||||
$this->comment($config['commentAbove'], 'above');
|
||||
}
|
||||
if (isset($config['comment'])) {
|
||||
$this->comment($config['comment']);
|
||||
}
|
||||
if (isset($config['placeholder'])) {
|
||||
$this->placeholder = $config['placeholder'];
|
||||
}
|
||||
if (isset($config['default'])) {
|
||||
$this->defaults = $config['default'];
|
||||
}
|
||||
if (isset($config['cssClass'])) {
|
||||
$this->cssClass = $config['cssClass'];
|
||||
}
|
||||
if (isset($config['attributes'])) {
|
||||
$this->attributes($config['attributes']);
|
||||
}
|
||||
if (isset($config['containerAttributes'])) {
|
||||
$this->attributes($config['containerAttributes'], 'container');
|
||||
}
|
||||
if (isset($config['depends'])) {
|
||||
$this->depends = $config['depends'];
|
||||
}
|
||||
if (isset($config['path'])) {
|
||||
$this->path = $config['path'];
|
||||
}
|
||||
|
||||
if (array_key_exists('required', $config)) $this->required = $config['required'];
|
||||
if (array_key_exists('disabled', $config)) $this->disabled = $config['disabled'];
|
||||
if (array_key_exists('hidden', $config)) $this->hidden = $config['hidden'];
|
||||
if (array_key_exists('stretch', $config)) $this->stretch = $config['stretch'];
|
||||
if (array_key_exists('required', $config)) {
|
||||
$this->required = $config['required'];
|
||||
}
|
||||
if (array_key_exists('disabled', $config)) {
|
||||
$this->disabled = $config['disabled'];
|
||||
}
|
||||
if (array_key_exists('hidden', $config)) {
|
||||
$this->hidden = $config['hidden'];
|
||||
}
|
||||
if (array_key_exists('stretch', $config)) {
|
||||
$this->stretch = $config['stretch'];
|
||||
}
|
||||
|
||||
if (isset($config['valueFrom'])) $this->valueFrom = $config['valueFrom'];
|
||||
else $this->valueFrom = $this->fieldName;
|
||||
if (isset($config['valueFrom'])) {
|
||||
$this->valueFrom = $config['valueFrom'];
|
||||
} else {
|
||||
$this->valueFrom = $this->fieldName;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
|
@ -284,8 +321,9 @@ class FormField
|
|||
*/
|
||||
public function attributes($items, $position = 'field')
|
||||
{
|
||||
if (!is_array($items))
|
||||
if (!is_array($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$multiArray = array_filter($items, 'is_array');
|
||||
if (!$multiArray) {
|
||||
|
|
@ -316,13 +354,15 @@ class FormField
|
|||
*/
|
||||
public function getName($arrayName = null)
|
||||
{
|
||||
if ($arrayName === null)
|
||||
if ($arrayName === null) {
|
||||
$arrayName = $this->arrayName;
|
||||
}
|
||||
|
||||
if ($arrayName)
|
||||
if ($arrayName) {
|
||||
return $arrayName.'['.implode('][', Str::evalHtmlArray($this->fieldName)).']';
|
||||
else
|
||||
} else {
|
||||
return $this->fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -331,17 +371,20 @@ class FormField
|
|||
public function getId($suffix = null)
|
||||
{
|
||||
$id = 'field';
|
||||
if ($this->arrayName)
|
||||
if ($this->arrayName) {
|
||||
$id .= '-'.$this->arrayName;
|
||||
}
|
||||
|
||||
$id .= '-'.$this->fieldName;
|
||||
|
||||
if ($suffix)
|
||||
if ($suffix) {
|
||||
$id .= '-'.$suffix;
|
||||
}
|
||||
|
||||
if ($this->idPrefix)
|
||||
if ($this->idPrefix) {
|
||||
$id = $this->idPrefix . '-' . $id;
|
||||
}
|
||||
|
||||
return Str::evalHtmlId($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,16 +61,23 @@ abstract class FormWidgetBase extends WidgetBase
|
|||
$this->valueFrom = $formField->valueFrom;
|
||||
$this->model = $model;
|
||||
|
||||
/* @todo Remove line if year >= 2015 */ $this->columnName = $formField->valueFrom;
|
||||
// @todo Remove line if year >= 2015
|
||||
$this->columnName = $formField->valueFrom;
|
||||
|
||||
if (isset($configuration->sessionKey)) $this->sessionKey = $configuration->sessionKey;
|
||||
if (isset($configuration->previewMode)) $this->previewMode = $configuration->previewMode;
|
||||
if (isset($configuration->sessionKey)) {
|
||||
$this->sessionKey = $configuration->sessionKey;
|
||||
}
|
||||
if (isset($configuration->previewMode)) {
|
||||
$this->previewMode = $configuration->previewMode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Form fields originally passed their configuration via the options index.
|
||||
* This step should be removed if year >= 2015.
|
||||
*/
|
||||
if (isset($configuration->options)) $configuration = array_merge($configuration->options, (array)$configuration);
|
||||
if (isset($configuration->options)) {
|
||||
$configuration = array_merge($configuration->options, (array)$configuration);
|
||||
}
|
||||
|
||||
parent::__construct($controller, $configuration);
|
||||
}
|
||||
|
|
@ -125,5 +132,4 @@ abstract class FormWidgetBase extends WidgetBase
|
|||
|
||||
return [$model, $last];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,19 +108,39 @@ class ListColumn
|
|||
*/
|
||||
protected function evalConfig($config)
|
||||
{
|
||||
if (isset($config['cssClass'])) $this->cssClass = $config['cssClass'];
|
||||
if (isset($config['searchable'])) $this->searchable = $config['searchable'];
|
||||
if (isset($config['sortable'])) $this->sortable = $config['sortable'];
|
||||
if (isset($config['invisible'])) $this->invisible = $config['invisible'];
|
||||
if (isset($config['valueFrom'])) $this->valueFrom = $config['valueFrom'];
|
||||
if (isset($config['select'])) $this->sqlSelect = $config['select'];
|
||||
if (isset($config['relation'])) $this->relation = $config['relation'];
|
||||
if (isset($config['format'])) $this->format = $config['format'];
|
||||
if (isset($config['path'])) $this->path = $config['path'];
|
||||
if (isset($config['cssClass'])) {
|
||||
$this->cssClass = $config['cssClass'];
|
||||
}
|
||||
if (isset($config['searchable'])) {
|
||||
$this->searchable = $config['searchable'];
|
||||
}
|
||||
if (isset($config['sortable'])) {
|
||||
$this->sortable = $config['sortable'];
|
||||
}
|
||||
if (isset($config['invisible'])) {
|
||||
$this->invisible = $config['invisible'];
|
||||
}
|
||||
if (isset($config['valueFrom'])) {
|
||||
$this->valueFrom = $config['valueFrom'];
|
||||
}
|
||||
if (isset($config['select'])) {
|
||||
$this->sqlSelect = $config['select'];
|
||||
}
|
||||
if (isset($config['relation'])) {
|
||||
$this->relation = $config['relation'];
|
||||
}
|
||||
if (isset($config['format'])) {
|
||||
$this->format = $config['format'];
|
||||
}
|
||||
if (isset($config['path'])) {
|
||||
$this->path = $config['path'];
|
||||
}
|
||||
|
||||
/* @todo Remove line if year >= 2015 */ if (isset($config['nameFrom'])) $this->valueFrom = $config['nameFrom'];
|
||||
// @todo Remove lines if year >= 2015
|
||||
if (isset($config['nameFrom'])) {
|
||||
$this->valueFrom = $config['nameFrom'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,8 +83,9 @@ class NavigationManager
|
|||
|
||||
foreach ($plugins as $id => $plugin) {
|
||||
$items = $plugin->registerNavigation();
|
||||
if (!is_array($items))
|
||||
if (!is_array($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->registerMenuItems($id, $items);
|
||||
}
|
||||
|
|
@ -97,9 +98,10 @@ class NavigationManager
|
|||
/*
|
||||
* Sort menu items
|
||||
*/
|
||||
usort($this->items, function($a, $b) {
|
||||
if ($a->order == $b->order)
|
||||
usort($this->items, function ($a, $b) {
|
||||
if ($a->order == $b->order) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $a->order > $b->order ? 1 : -1;
|
||||
});
|
||||
|
|
@ -111,8 +113,9 @@ class NavigationManager
|
|||
$this->items = $this->filterItemPermissions($user, $this->items);
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
if (!$item->sideMenu || !count($item->sideMenu))
|
||||
if (!$item->sideMenu || !count($item->sideMenu)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item->sideMenu = $this->filterItemPermissions($user, $item->sideMenu);
|
||||
}
|
||||
|
|
@ -161,8 +164,9 @@ class NavigationManager
|
|||
*/
|
||||
public function registerMenuItems($owner, array $definitions)
|
||||
{
|
||||
if (!$this->items)
|
||||
if (!$this->items) {
|
||||
$this->items = [];
|
||||
}
|
||||
|
||||
foreach ($definitions as $code => $definition) {
|
||||
$item = (object) array_merge(self::$mainItemDefaults, array_merge($definition, [
|
||||
|
|
@ -192,8 +196,9 @@ class NavigationManager
|
|||
*/
|
||||
public function addMainMenuItems($owner, array $definitions)
|
||||
{
|
||||
foreach ($definitions as $code => $definition)
|
||||
foreach ($definitions as $code => $definition) {
|
||||
$this->addMainMenuItem($owner, $code, $definition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -207,8 +212,9 @@ class NavigationManager
|
|||
$sideMenu = isset($definition['sideMenu']) ? $definition['sideMenu'] : null;
|
||||
|
||||
$itemKey = $this->makeItemKey($owner, $code);
|
||||
if (isset($this->items[$itemKey]))
|
||||
if (isset($this->items[$itemKey])) {
|
||||
$definition = array_merge((array) $this->items[$itemKey], $definition);
|
||||
}
|
||||
|
||||
$item = (object) array_merge(self::$mainItemDefaults, array_merge($definition, [
|
||||
'code' => $code,
|
||||
|
|
@ -217,8 +223,9 @@ class NavigationManager
|
|||
|
||||
$this->items[$itemKey] = $item;
|
||||
|
||||
if ($sideMenu !== null)
|
||||
if ($sideMenu !== null) {
|
||||
$this->addSideMenuItems($sideMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -229,8 +236,9 @@ class NavigationManager
|
|||
*/
|
||||
public function addSideMenuItems($owner, $code, array $definitions)
|
||||
{
|
||||
foreach ($definitions as $sideCode => $definition)
|
||||
foreach ($definitions as $sideCode => $definition) {
|
||||
$this->addSideMenuItem($owner, $code, $sideCode, $definition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -243,12 +251,14 @@ class NavigationManager
|
|||
public function addSideMenuItem($owner, $code, $sideCode, array $definition)
|
||||
{
|
||||
$itemKey = $this->makeItemKey($owner, $code);
|
||||
if (!isset($this->items[$itemKey]))
|
||||
if (!isset($this->items[$itemKey])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mainItem = $this->items[$itemKey];
|
||||
if (isset($mainItem->sideMenu[$sideCode]))
|
||||
if (isset($mainItem->sideMenu[$sideCode])) {
|
||||
$definition = array_merge((array) $mainItem->sideMenu[$sideCode], $definition);
|
||||
}
|
||||
|
||||
$item = (object) array_merge(self::$sideItemDefaults, $definition);
|
||||
$this->items[$itemKey]->sideMenu[$sideCode] = $item;
|
||||
|
|
@ -260,8 +270,9 @@ class NavigationManager
|
|||
*/
|
||||
public function listMainMenuItems()
|
||||
{
|
||||
if ($this->items === null)
|
||||
if ($this->items === null) {
|
||||
$this->loadItems();
|
||||
}
|
||||
|
||||
return $this->items;
|
||||
}
|
||||
|
|
@ -281,14 +292,16 @@ class NavigationManager
|
|||
}
|
||||
}
|
||||
|
||||
if (!$activeItem)
|
||||
if (!$activeItem) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$items = $activeItem->sideMenu;
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->counter !== null && is_callable($item->counter))
|
||||
if ($item->counter !== null && is_callable($item->counter)) {
|
||||
$item->counter = call_user_func($item->counter, $item);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
|
@ -339,7 +352,7 @@ class NavigationManager
|
|||
return (object)[
|
||||
'mainMenuCode' => $this->contextMainMenuItemCode,
|
||||
'sideMenuCode' => $this->contextSideMenuItemCode,
|
||||
'owner' => $this->contextOwner
|
||||
'owner' => $this->contextOwner
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -369,8 +382,9 @@ class NavigationManager
|
|||
public function getActiveMainMenuItem()
|
||||
{
|
||||
foreach ($this->listMainMenuItems() as $item) {
|
||||
if ($this->isMainMenuItemActive($item))
|
||||
if ($this->isMainMenuItemActive($item)) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -399,7 +413,9 @@ class NavigationManager
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method.
|
||||
* Returns the side navigation partial for a specific main menu previously registered
|
||||
* with the registerContextSidenavPartial() method.
|
||||
*
|
||||
* @param string $owner Specifies the navigation owner in the format Vendor/Module.
|
||||
* @param string $mainMenuItemCode Specifies the main menu item code.
|
||||
* @return mixed Returns the partial name or null.
|
||||
|
|
@ -408,7 +424,7 @@ class NavigationManager
|
|||
{
|
||||
$key = $owner.$mainMenuItemCode;
|
||||
|
||||
return array_key_exists($key, $this->contextSidenavPartials) ?
|
||||
return array_key_exists($key, $this->contextSidenavPartials) ?
|
||||
$this->contextSidenavPartials[$key] :
|
||||
null;
|
||||
}
|
||||
|
|
@ -421,9 +437,10 @@ class NavigationManager
|
|||
*/
|
||||
protected function filterItemPermissions($user, array $items)
|
||||
{
|
||||
$items = array_filter($items, function($item) use ($user) {
|
||||
if (!$item->permissions || !count($item->permissions))
|
||||
$items = array_filter($items, function ($item) use ($user) {
|
||||
if (!$item->permissions || !count($item->permissions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->hasAnyAccess($item->permissions);
|
||||
});
|
||||
|
|
@ -440,4 +457,4 @@ class NavigationManager
|
|||
{
|
||||
return strtoupper($owner).'.'.strtoupper($code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@ class ReportWidgetBase extends WidgetBase
|
|||
|
||||
parent::__construct($controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@ abstract class Skin
|
|||
return $isPublic
|
||||
? $this->publicSkinPath . $path
|
||||
: $this->skinPath . $path;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $isPublic
|
||||
? $this->defaultPublicSkinPath . $path
|
||||
: $this->defaultSkinPath . $path;
|
||||
|
|
@ -101,11 +100,12 @@ abstract class Skin
|
|||
*/
|
||||
public static function getActive()
|
||||
{
|
||||
if (self::$skinCache !== null)
|
||||
if (self::$skinCache !== null) {
|
||||
return self::$skinCache;
|
||||
}
|
||||
|
||||
$skinClass = Config::get('cms.backendSkin');
|
||||
$skinObject = new $skinClass();
|
||||
return self::$skinCache = $skinObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ abstract class WidgetBase
|
|||
|
||||
// Option A: (@todo Determine which is faster by benchmark)
|
||||
// $relativePath = strtolower(str_replace('\\', '/', get_called_class()));
|
||||
// $this->viewPath = $this->configPath = ['modules/' . $relativePath . '/partials', 'plugins/' . $relativePath . '/partials'];
|
||||
// $this->viewPath = $this->configPath = [
|
||||
// 'modules/' . $relativePath . '/partials',
|
||||
// 'plugins/' . $relativePath . '/partials'
|
||||
// ];
|
||||
// $this->assetPath = ['modules/' . $relativePath . '/assets', 'plugins/' . $relativePath . '/assets'];
|
||||
|
||||
// Option B:
|
||||
|
|
@ -62,16 +65,18 @@ abstract class WidgetBase
|
|||
/*
|
||||
* Apply configuration values to a new config object.
|
||||
*/
|
||||
if (!$configuration)
|
||||
if (!$configuration) {
|
||||
$configuration = [];
|
||||
}
|
||||
|
||||
$this->config = $this->makeConfig($configuration);
|
||||
|
||||
/*
|
||||
* If no alias is set by the configuration.
|
||||
*/
|
||||
if (!isset($this->alias))
|
||||
if (!isset($this->alias)) {
|
||||
$this->alias = (isset($this->config->alias)) ? $this->config->alias : $this->defaultAlias;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare assets used by this widget.
|
||||
|
|
@ -81,28 +86,35 @@ abstract class WidgetBase
|
|||
/*
|
||||
* Initialize the widget.
|
||||
*/
|
||||
if (!$this->getConfig('noInit', false))
|
||||
if (!$this->getConfig('noInit', false)) {
|
||||
$this->init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the widget, called by the constructor and free from its parameters.
|
||||
* @return void
|
||||
*/
|
||||
public function init(){}
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the widgets primary contents.
|
||||
* @return string HTML markup supplied by this widget.
|
||||
*/
|
||||
public function render(){}
|
||||
public function render()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds widget specific asset files. Use $this->addJs() and $this->addCss()
|
||||
* to register new assets to include on the page.
|
||||
* @return void
|
||||
*/
|
||||
protected function loadAssets(){}
|
||||
protected function loadAssets()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a widget to the controller for safe use.
|
||||
|
|
@ -110,8 +122,9 @@ abstract class WidgetBase
|
|||
*/
|
||||
public function bindToController()
|
||||
{
|
||||
if ($this->controller->widget === null)
|
||||
if ($this->controller->widget === null) {
|
||||
$this->controller->widget = new \stdClass();
|
||||
}
|
||||
|
||||
$this->controller->widget->{$this->alias} = $this;
|
||||
}
|
||||
|
|
@ -125,11 +138,13 @@ abstract class WidgetBase
|
|||
{
|
||||
$id = class_basename(get_called_class());
|
||||
|
||||
if ($this->alias != $this->defaultAlias)
|
||||
if ($this->alias != $this->defaultAlias) {
|
||||
$id .= '-' . $this->alias;
|
||||
}
|
||||
|
||||
if ($suffix !== null)
|
||||
if ($suffix !== null) {
|
||||
$id .= '-' . $suffix;
|
||||
}
|
||||
|
||||
return Str::evalHtmlId($id);
|
||||
}
|
||||
|
|
@ -161,8 +176,9 @@ abstract class WidgetBase
|
|||
* First part will be the field name, pop it off
|
||||
*/
|
||||
$fieldName = array_shift($keyParts);
|
||||
if (!isset($this->config->{$fieldName}))
|
||||
if (!isset($this->config->{$fieldName})) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$result = $this->config->{$fieldName};
|
||||
|
||||
|
|
@ -170,8 +186,9 @@ abstract class WidgetBase
|
|||
* Loop the remaining key parts and build a result
|
||||
*/
|
||||
foreach ($keyParts as $key) {
|
||||
if (!array_key_exists($key, $result))
|
||||
if (!array_key_exists($key, $result)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$result = $result[$key];
|
||||
}
|
||||
|
|
@ -218,11 +235,13 @@ abstract class WidgetBase
|
|||
$sessionId = $this->makeSessionId();
|
||||
|
||||
$currentStore = [];
|
||||
if (Session::has($sessionId))
|
||||
if (Session::has($sessionId)) {
|
||||
$currentStore = unserialize(Session::get($sessionId));
|
||||
}
|
||||
|
||||
if ($key === null)
|
||||
if ($key === null) {
|
||||
return $currentStore;
|
||||
}
|
||||
|
||||
return isset($currentStore[$key]) ? $currentStore[$key] : $default;
|
||||
}
|
||||
|
|
@ -247,5 +266,4 @@ abstract class WidgetBase
|
|||
$sessionId = $this->makeSessionId();
|
||||
Session::forget($sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,8 +84,9 @@ class WidgetManager
|
|||
/*
|
||||
* Build configuration
|
||||
*/
|
||||
if ($configuration === null)
|
||||
if ($configuration === null) {
|
||||
$configuration = [];
|
||||
}
|
||||
|
||||
/*
|
||||
* Create widget object
|
||||
|
|
@ -125,11 +126,13 @@ class WidgetManager
|
|||
$plugins = $this->pluginManager->getPlugins();
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
if (!is_array($widgets = $plugin->registerFormWidgets()))
|
||||
if (!is_array($widgets = $plugin->registerFormWidgets())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($widgets as $className => $widgetInfo)
|
||||
foreach ($widgets as $className => $widgetInfo) {
|
||||
$this->registerFormWidget($className, $widgetInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,8 +148,9 @@ class WidgetManager
|
|||
public function registerFormWidget($className, $widgetInfo = null)
|
||||
{
|
||||
$widgetAlias = isset($widgetInfo['alias']) ? $widgetInfo['alias'] : null;
|
||||
if (!$widgetAlias)
|
||||
if (!$widgetAlias) {
|
||||
$widgetAlias = Str::getClassId($className);
|
||||
}
|
||||
|
||||
$this->formWidgets[$className] = $widgetInfo;
|
||||
$this->formWidgetAliases[$widgetAlias] = $className;
|
||||
|
|
@ -175,17 +179,20 @@ class WidgetManager
|
|||
*/
|
||||
public function resolveFormWidget($name)
|
||||
{
|
||||
if ($this->formWidgets === null)
|
||||
if ($this->formWidgets === null) {
|
||||
$this->listFormWidgets();
|
||||
}
|
||||
|
||||
$aliases = $this->formWidgetAliases;
|
||||
|
||||
if (isset($aliases[$name]))
|
||||
if (isset($aliases[$name])) {
|
||||
return $aliases[$name];
|
||||
}
|
||||
|
||||
$_name = Str::normalizeClassName($name);
|
||||
if (isset($this->formWidgets[$_name]))
|
||||
if (isset($this->formWidgets[$_name])) {
|
||||
return $_name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
|
@ -216,11 +223,13 @@ class WidgetManager
|
|||
$plugins = $this->pluginManager->getPlugins();
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
if (!is_array($widgets = $plugin->registerReportWidgets()))
|
||||
if (!is_array($widgets = $plugin->registerReportWidgets())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($widgets as $className => $widgetInfo)
|
||||
foreach ($widgets as $className => $widgetInfo) {
|
||||
$this->registerReportWidget($className, $widgetInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -251,4 +260,4 @@ class WidgetManager
|
|||
{
|
||||
$this->reportWidgetCallbacks[] = $definitions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue