From 3d164d88b7c764076ad1df99b073f1a1fe0e10d5 Mon Sep 17 00:00:00 2001 From: Michael van Schaik Date: Wed, 15 Dec 2021 09:30:16 +0100 Subject: [PATCH] Making 'edit original' link conditional (only show if linked) Fixes #46 --- src/Model/ElementVirtual.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Model/ElementVirtual.php b/src/Model/ElementVirtual.php index 4f32720..9a0bb41 100644 --- a/src/Model/ElementVirtual.php +++ b/src/Model/ElementVirtual.php @@ -56,12 +56,6 @@ public function getCMSFields() $this->beforeUpdateCMSFields(function (FieldList $fields) use ($invalid) { $fields->removeByName('Title'); - $message = sprintf( - '

%s

Click here to edit the original

', - _t(__CLASS__ . '.VirtualDescription', 'This is a virtual copy of an element.'), - $this->LinkedElement()->getEditLink() - ); - if ($invalid) { $warning = _t( __CLASS__ . '.InvalidPublishStateWarning', @@ -86,7 +80,15 @@ public function getCMSFields() 'LinkedElementID', $autocomplete ); - $fields->addFieldToTab('Root.Main', LiteralField::create('Existing', $message)); + + if($this->LinkedElementID){ + $message = sprintf( + '

%s

Click here to edit the original

', + _t(__CLASS__ . '.VirtualDescription', 'This is a virtual copy of an element.'), + $this->LinkedElement()->getEditLink() + ); + $fields->addFieldToTab('Root.Main', LiteralField::create('Existing', $message)); + } }); return parent::getCMSFields();