diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index 2e2b3b8c4f..e15462fcd7 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -3,7 +3,9 @@ use Db; use Backend\Classes\FormField; use Backend\Classes\FormWidgetBase; +use Lang; use Winter\Storm\Database\Relations\Relation as RelationBase; +use Winter\Storm\Exception\SystemException; /** * Form Relationship @@ -95,6 +97,7 @@ public function prepareVars() /** * Makes the form object used for rendering a simple field type + * @throws SystemException if an unsupported relation type is used. */ protected function makeRenderFormField() { @@ -110,9 +113,14 @@ protected function makeRenderFormField() if (in_array($relationType, ['belongsToMany', 'morphToMany', 'morphedByMany', 'hasMany'])) { $field->type = 'checkboxlist'; - } - elseif (in_array($relationType, ['belongsTo', 'hasOne'])) { + } elseif (in_array($relationType, ['belongsTo', 'hasOne'])) { $field->type = 'dropdown'; + } else { + throw new SystemException( + Lang::get('backend::lang.relation.relationwidget_unsupported_type', [ + 'type' => $relationType + ]) + ); } // Order query by the configured option. diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 6fbafc7a96..6fe8b20f31 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -320,6 +320,7 @@ 'missing_model' => 'Relation behavior used in :class does not have a model defined.', 'invalid_action_single' => 'This action cannot be performed on a singular relationship.', 'invalid_action_multi' => 'This action cannot be performed on a multiple relationship.', + 'relationwidget_unsupported_type' => 'The ":type" relation type is unsupported by the Relation widget.', 'help' => 'Click on an item to add', 'related_data' => 'Related :name data', 'add' => 'Add', diff --git a/modules/backend/lang/fr/lang.php b/modules/backend/lang/fr/lang.php index 13a5ee534a..bc3ded4eac 100644 --- a/modules/backend/lang/fr/lang.php +++ b/modules/backend/lang/fr/lang.php @@ -297,6 +297,7 @@ 'missing_model' => 'La behavior relation utilisée dans la classe :class n’a pas de modèle défini.', 'invalid_action_single' => 'Cette action ne peut être effectuée sur une relation unitaire.', 'invalid_action_multi' => 'Cette action ne peut être effectuée sur une relation multiple.', + 'relationwidget_unsupported_type' => 'Le type de relation ":type" n\'est pas supporté par le widget Relation.', 'help' => 'Cliquer sur un élément pour l’ajouter', 'related_data' => 'Donnée :name liée', 'add' => 'Ajouter',