From 8428787713a841a2e03a075091741f6facd55b84 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Wed, 17 Apr 2019 23:49:02 +0200
Subject: [PATCH] [BUGFIX] Don't show new button when adding a new record

As there is no "pid" available, the new button on new
records should not be shown.

Resolves: #87721
Releases: master, 9.5
Change-Id: Ie3521882e38f031d3362de841351b058faed9521
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60506
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Josef Glatz <josefglatz@gmail.com>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Josef Glatz <josefglatz@gmail.com>
Reviewed-by: Susanne Moog <look@susi.dev>
---
 .../Controller/EditDocumentController.php     | 30 ++++++++++---------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
index d4cecdf669c6..1ebb040d2fba 100644
--- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
+++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php
@@ -1227,20 +1227,22 @@ class EditDocumentController
         ) {
             $this->registerSaveButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_LEFT, 2);
             $this->registerViewButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_LEFT, 3);
-            $this->registerNewButtonToButtonBar(
-                $buttonBar,
-                ButtonBar::BUTTON_POSITION_LEFT,
-                4,
-                $sysLanguageUid,
-                $l18nParent
-            );
-            $this->registerDuplicationButtonToButtonBar(
-                $buttonBar,
-                ButtonBar::BUTTON_POSITION_LEFT,
-                5,
-                $sysLanguageUid,
-                $l18nParent
-            );
+            if ($this->firstEl['cmd'] !== 'new') {
+                $this->registerNewButtonToButtonBar(
+                    $buttonBar,
+                    ButtonBar::BUTTON_POSITION_LEFT,
+                    4,
+                    $sysLanguageUid,
+                    $l18nParent
+                );
+                $this->registerDuplicationButtonToButtonBar(
+                    $buttonBar,
+                    ButtonBar::BUTTON_POSITION_LEFT,
+                    5,
+                    $sysLanguageUid,
+                    $l18nParent
+                );
+            }
             $this->registerDeleteButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_LEFT, 6);
             $this->registerColumnsOnlyButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_LEFT, 7);
             $this->registerHistoryButtonToButtonBar($buttonBar, ButtonBar::BUTTON_POSITION_RIGHT, 1);
-- 
GitLab