From c84c51c82009a84b546e5b8acdd9314906ceb162 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sun, 28 Jun 2020 10:57:47 -0600 Subject: [PATCH 1/3] Improve error message when attempting to fork an unforkable component. Fixes #5142 and rainlab/forum-plugin#141 --- modules/cms/controllers/Index.php | 5 +++++ modules/cms/lang/en/lang.php | 1 + 2 files changed, 6 insertions(+) diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index 617e91bc3..094fdb7a9 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -403,6 +403,11 @@ class Index extends Controller $manager = ComponentManager::instance(); $componentObj = $manager->makeComponent($componentName); $partial = ComponentPartial::load($componentObj, 'default'); + + if (!$partial) { + throw new ApplicationException(Lang::get('cms::lang.component.no_default_partial')); + } + $content = $partial->getContent(); $content = str_replace('__SELF__', $alias, $content); diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index 66bad48cb..215bff893 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -249,6 +249,7 @@ return [ 'invalid_request' => 'The template cannot be saved because of invalid component data.', 'no_records' => 'No components found', 'not_found' => "The component ':name' is not found.", + 'no_default_partial' => "This component does not have a 'default' partial", 'method_not_found' => "The component ':name' does not contain a method ':method'.", 'soft_component' => 'Soft Component', 'soft_component_description' => 'This component is missing but optional.', From dea03a698c9e6031db03c5b9ce3533c9a8ea4d8f Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sun, 28 Jun 2020 11:14:35 -0600 Subject: [PATCH 2/3] Use the Lang facade rather than the trans helper function --- modules/cms/controllers/Index.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index 094fdb7a9..a99cd8e7f 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -134,7 +134,7 @@ class Index extends Controller $this->bodyClass = 'compact-container'; $this->pageTitle = 'cms::lang.cms.menu_label'; - $this->pageTitleTemplate = '%s '.trans($this->pageTitle); + $this->pageTitleTemplate = '%s '.Lang::get($this->pageTitle); if (Request::ajax() && Request::input('formWidgetAlias')) { $this->bindFormWidgetToController(); @@ -380,7 +380,7 @@ class Index extends Controller public function onExpandMarkupToken() { if (!$alias = post('tokenName')) { - throw new ApplicationException(trans('cms::lang.component.no_records')); + throw new ApplicationException(Lang::get('cms::lang.component.no_records')); } // Can only expand components at this stage @@ -389,15 +389,15 @@ class Index extends Controller } if (!($names = (array) post('component_names')) || !($aliases = (array) post('component_aliases'))) { - throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + throw new ApplicationException(Lang::get('cms::lang.component.not_found', ['name' => $alias])); } if (($index = array_get(array_flip($aliases), $alias, false)) === false) { - throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + throw new ApplicationException(Lang::get('cms::lang.component.not_found', ['name' => $alias])); } if (!$componentName = array_get($names, $index)) { - throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + throw new ApplicationException(Lang::get('cms::lang.component.not_found', ['name' => $alias])); } $manager = ComponentManager::instance(); @@ -556,7 +556,7 @@ class Index extends Controller protected function validateRequestTheme() { if ($this->theme->getDirName() != Request::input('theme')) { - throw new ApplicationException(trans('cms::lang.theme.edit.not_match')); + throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_match')); } } @@ -576,7 +576,7 @@ class Index extends Controller ]; if (!array_key_exists($type, $types)) { - throw new ApplicationException(trans('cms::lang.template.invalid_type')); + throw new ApplicationException(Lang::get('cms::lang.template.invalid_type')); } return $types[$type]; @@ -593,7 +593,7 @@ class Index extends Controller $class = $this->resolveTypeClassName($type); if (!($template = call_user_func([$class, 'load'], $this->theme, $path))) { - throw new ApplicationException(trans('cms::lang.template.not_found')); + throw new ApplicationException(Lang::get('cms::lang.template.not_found')); } /** @@ -628,7 +628,7 @@ class Index extends Controller $class = $this->resolveTypeClassName($type); if (!($template = $class::inTheme($this->theme))) { - throw new ApplicationException(trans('cms::lang.template.not_found')); + throw new ApplicationException(Lang::get('cms::lang.template.not_found')); } return $template; @@ -645,7 +645,7 @@ class Index extends Controller if ($type === 'page') { $result = $template->title ?: $template->getFileName(); if (!$result) { - $result = trans('cms::lang.page.new'); + $result = Lang::get('cms::lang.page.new'); } return $result; @@ -654,7 +654,7 @@ class Index extends Controller if ($type === 'partial' || $type === 'layout' || $type === 'content' || $type === 'asset') { $result = in_array($type, ['asset', 'content']) ? $template->getFileName() : $template->getBaseFileName(); if (!$result) { - $result = trans('cms::lang.'.$type.'.new'); + $result = Lang::get('cms::lang.'.$type.'.new'); } return $result; @@ -681,7 +681,7 @@ class Index extends Controller ]; if (!array_key_exists($type, $formConfigs)) { - throw new ApplicationException(trans('cms::lang.template.not_found')); + throw new ApplicationException(Lang::get('cms::lang.template.not_found')); } $widgetConfig = $this->makeConfig($formConfigs[$type]); @@ -708,12 +708,12 @@ class Index extends Controller if ($componentProperties !== null) { if ($componentNames === null || $componentAliases === null) { - throw new ApplicationException(trans('cms::lang.component.invalid_request')); + throw new ApplicationException(Lang::get('cms::lang.component.invalid_request')); } $count = count($componentProperties); if (count($componentNames) != $count || count($componentAliases) != $count) { - throw new ApplicationException(trans('cms::lang.component.invalid_request')); + throw new ApplicationException(Lang::get('cms::lang.component.invalid_request')); } for ($index = 0; $index < $count; $index++) { From 9082a231a6030dc3191ff86088cd624922a3e345 Mon Sep 17 00:00:00 2001 From: Meysam Date: Wed, 1 Jul 2020 04:11:16 +0200 Subject: [PATCH 3/3] Document Select2's dynamic option creation (#5052) --- modules/system/assets/ui/docs/select.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/system/assets/ui/docs/select.md b/modules/system/assets/ui/docs/select.md index 871698389..c2c6e2cc8 100644 --- a/modules/system/assets/ui/docs/select.md +++ b/modules/system/assets/ui/docs/select.md @@ -43,6 +43,15 @@ Add the `select-no-search` CSS class to disable searching. +### Dynamic option creation + +In addition to a pre-populated menu of options, Select widgets may dynamically create new options from textual input by the user in the search box. This feature is called "tagging". To enable tagging, set the `tags` option to `true`: + + + ## Option groups Use the `optgroup` element to create option groups.