Skip to content

Commit

Permalink
warn the user they need to implement the RelationController bevior
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Oct 16, 2023
1 parent 402d2ba commit 06fe760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/backend/formwidgets/RelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Backend\FormWidgets;

use ApplicationException;
use Backend\Classes\FormField;
use Backend\Classes\FormWidgetBase;
use Lang;

class RelationManager extends FormWidgetBase
{
Expand Down Expand Up @@ -42,6 +44,13 @@ public function init(): void

public function render()
{
if (!$this->controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class)) {
$error = Lang::get('backend::lang.relation.missing_behavior', [
'controller' => get_class($this->controller)
]);
throw new ApplicationException($error);
}

$options = [
'readOnly' => $this->readOnly,
'recordUrl' => $this->recordUrl,
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 @@ -319,6 +319,7 @@
'select_page' => 'Select a page...',
],
'relation' => [
'missing_behavior' => 'You must implement the RelationController behavior in your :controller controller.',
'missing_config' => "Relation behavior does not have any configuration for ':config'.",
'missing_definition' => "Relation behavior does not contain a definition for ':field'.",
'missing_model' => 'Relation behavior used in :class does not have a model defined.',
Expand Down

0 comments on commit 06fe760

Please sign in to comment.