Add validator for plugin navigation items (#4497)
This will detect invalid navigation item configuration in installed plugins. In debug mode, this will throw an error, otherwise, it will simply log the error. Credit to @Samuell1. Fixes #4491.
This commit is contained in:
parent
60a235e000
commit
9b8974b003
|
|
@ -3,6 +3,10 @@
|
|||
use Event;
|
||||
use BackendAuth;
|
||||
use System\Classes\PluginManager;
|
||||
use Validator;
|
||||
use SystemException;
|
||||
use Log;
|
||||
use Config;
|
||||
|
||||
/**
|
||||
* Manages the backend navigation.
|
||||
|
|
@ -195,6 +199,24 @@ class NavigationManager
|
|||
$this->items = [];
|
||||
}
|
||||
|
||||
$validator = Validator::make($definitions, [
|
||||
'*.label' => 'required',
|
||||
'*.icon' => 'required_without:*.iconSvg',
|
||||
'*.url' => 'required',
|
||||
'*.sideMenu.*.label' => 'nullable|required',
|
||||
'*.sideMenu.*.icon' => 'nullable|required_without:*.sideMenu.*.iconSvg',
|
||||
'*.sideMenu.*.url' => 'nullable|required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
$errorMessage = 'Invalid menu item detected in ' . $owner . '. Contact the plugin author to fix (' . $validator->errors()->first() . ')';
|
||||
if (Config::get('app.debug', false)) {
|
||||
throw new SystemException($errorMessage);
|
||||
} else {
|
||||
Log::error($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addMainMenuItems($owner, $definitions);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue