From 3d2496d4003666c60fbb83f419958a4487885d2d Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Wed, 22 May 2024 11:15:34 -0600 Subject: [PATCH] Don't override RelationController config in RelationManager unless explicitly set --- .../backend/formwidgets/RelationManager.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/backend/formwidgets/RelationManager.php b/modules/backend/formwidgets/RelationManager.php index 577f50017..b1165885a 100644 --- a/modules/backend/formwidgets/RelationManager.php +++ b/modules/backend/formwidgets/RelationManager.php @@ -4,8 +4,8 @@ use Backend\Classes\FormField; use Backend\Classes\FormWidgetBase; -use Lang; -use SystemException; +use Illuminate\Support\Facades\Lang; +use Winter\Storm\Exception\SystemException; class RelationManager extends FormWidgetBase { @@ -17,17 +17,17 @@ class RelationManager extends FormWidgetBase /** * Disables the ability to add, update, delete or create relations. */ - protected bool $readOnly = false; + protected ?bool $readOnly = null; /** * Path to controller action to open a record. */ - protected string $recordUrl = ''; + protected ?string $recordUrl = null; /** * Custom JavaScript code to execute when clicking on a record. */ - protected string $recordOnClick = ''; + protected ?string $recordOnClick = null; /** * Relation name if different from the field name. @@ -43,7 +43,7 @@ public function init(): void 'relation', ]); - if (!isset($this->readOnly)) { + if (!isset($this->readOnly) && $this->config->previewMode) { $this->readOnly = $this->config->previewMode; } } @@ -58,12 +58,17 @@ public function render() throw new SystemException($error); } - $options = [ - 'readOnly' => $this->readOnly, - 'recordUrl' => $this->recordUrl, - ]; + $options = []; - if ($this->recordOnClick) { + if (!is_null($this->readOnly)) { + $options['readOnly'] = $this->readOnly; + } + + if (!is_null($this->recordUrl)) { + $options['recordUrl'] = $this->recordUrl; + } + + if (!is_null($this->recordOnClick)) { $options['recordOnClick'] = $this->recordOnClick; }