Skip to content

Commit

Permalink
Don't override RelationController config in RelationManager unless ex…
Browse files Browse the repository at this point in the history
…plicitly set
  • Loading branch information
LukeTowers committed May 22, 2024
1 parent ddca17f commit 3d2496d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions modules/backend/formwidgets/RelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 3d2496d

Please sign in to comment.