diff --git a/modules/system/controllers/Settings.php b/modules/system/controllers/Settings.php index 7ba29dea7..719dff20e 100644 --- a/modules/system/controllers/Settings.php +++ b/modules/system/controllers/Settings.php @@ -2,6 +2,8 @@ use Lang; use Flash; +use Config; +use Request; use Backend; use BackendMenu; use System\Classes\SettingsManager; @@ -139,6 +141,22 @@ class Settings extends Controller return $this->formWidget->render($options); } + /** + * Returns the form widget used by this behavior. + * + * @return \Backend\Widgets\Form + */ + public function formGetWidget() + { + if (is_null($this->formWidget)) { + $item = $this->findSettingItem(); + $model = $this->createModel($item); + $this->initWidgets($model); + } + + return $this->formWidget; + } + /** * Prepare the widgets used by this action * Model $model @@ -169,10 +187,22 @@ class Settings extends Controller } /** - * Locates a setting item for a module or plugin + * Locates a setting item for a module or plugin. + * + * If none of the parameters are provided, they will be auto-guessed from the URL. + * + * @param string|null $author + * @param string|null $plugin + * @param string|null $code + * + * @return array */ - protected function findSettingItem($author, $plugin, $code) + protected function findSettingItem($author = null, $plugin = null, $code = null) { + if (is_null($author) || is_null($plugin)) { + [$author, $plugin, $code] = $this->guessSettingItem(); + } + $manager = SettingsManager::instance(); $moduleOwner = $author; @@ -187,4 +217,23 @@ class Settings extends Controller return $item; } + + /** + * Guesses the requested setting item from the current URL segments provided by the Request object. + * + * @return array + */ + protected function guessSettingItem() + { + $segments = Request::segments(); + + if (!empty(Config::get('cms.backendUri', 'backend'))) { + array_splice($segments, 0, 4); + } else { + array_splice($segments, 0, 3); + } + + // Ensure there's at least 3 segments + return array_pad($segments, 3, null); + } }