From 06fe76082baebb8aae7b4e299a6751e7885a5dc4 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 16 Oct 2023 09:46:16 -0400 Subject: [PATCH] warn the user they need to implement the RelationController bevior --- modules/backend/formwidgets/RelationManager.php | 9 +++++++++ modules/backend/lang/en/lang.php | 1 + 2 files changed, 10 insertions(+) diff --git a/modules/backend/formwidgets/RelationManager.php b/modules/backend/formwidgets/RelationManager.php index 85c3ea2770..ed13ef4de0 100644 --- a/modules/backend/formwidgets/RelationManager.php +++ b/modules/backend/formwidgets/RelationManager.php @@ -2,8 +2,10 @@ namespace Backend\FormWidgets; +use ApplicationException; use Backend\Classes\FormField; use Backend\Classes\FormWidgetBase; +use Lang; class RelationManager extends FormWidgetBase { @@ -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, diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index a23509f1d1..8dc7ee9bb2 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -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.',