From 17f3687165955f5977a3b278aec7a3147c20228f Mon Sep 17 00:00:00 2001 From: David Molineus Date: Tue, 12 May 2020 09:40:25 +0200 Subject: [PATCH] Do not add all translation ids if tree is not open --- src/Driver.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Driver.php b/src/Driver.php index cd780f2..fa4f175 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -13,6 +13,7 @@ use Contao\CoreBundle\Exception\AccessDeniedException; use Contao\CoreBundle\Exception\InternalServerErrorException; +use Contao\System; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -838,12 +839,18 @@ protected function generateTree($table, $id, $arrPrevNext, $blnHasSorting, $intM // Now that there's $arrFound we can just add all that main languages to the found array // so it will never show translated items and we don't have to override the whole method // anymore - hurray! - $translationIds = \Database::getInstance()->prepare( - "SELECT id FROM " . $table . " WHERE pid=? AND $langColumn=''") - ->execute($id) - ->fetchEach('id'); - - $arrFound = array_merge($arrFound, $translationIds); + $objSessionBag = System::getContainer()->get('session')->getBag('contao_backend'); + $session = $objSessionBag->all(); + $node = ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) ? $this->strTable . '_' . $table . '_tree' : $this->strTable . '_tree'; + $blnIsOpen = (!empty($arrFound) || $session[$node][$id] == 1); + if ($blnIsOpen) { + $translationIds = \Database::getInstance()->prepare( + "SELECT id FROM " . $table . " WHERE pid=? AND $langColumn=''") + ->execute($id) + ->fetchEach('id'); + + $arrFound = array_merge($arrFound, $translationIds); + } // Do not display the language records in the child list if ($table === $this->strTable && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] === 6) {