Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions modules/backend/formwidgets/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions modules/backend/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions modules/backend/lang/fr/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down