[FEATURE] Exclude or include pages and/or subpages with translations 07/58607/6
authorCybercraft <info@cybercraft.de>
Wed, 10 Oct 2018 11:34:48 +0000 (13:34 +0200)
committerJo Hasenau <info@cybercraft.de>
Thu, 13 Dec 2018 07:12:38 +0000 (08:12 +0100)
Change-Id: I53a35871e18768f623341d7492dca9e43cd8941d
Resolves: #30098
Releases: master, 8-0
Reviewed-on: https://review.typo3.org/58607
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
Classes/Constants.php [new file with mode: 0644]
Classes/Model/L10nAccumulatedInformation.php
Configuration/TCA/Overrides/pages.php [new file with mode: 0644]
Resources/Private/Language/locallang_db.xlf
ext_localconf.php
ext_tables.sql

diff --git a/Classes/Constants.php b/Classes/Constants.php
new file mode 100644 (file)
index 0000000..2ee0fcc
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+namespace Localizationteam\L10nmgr;
+
+/**
+ * Constants for the L10nmgr
+ */
+
+class Constants
+{
+    const L10NMGR_CONFIGURATION_DEFAULT = 0;
+    const L10NMGR_CONFIGURATION_NONE = 1;
+    const L10NMGR_CONFIGURATION_EXCLUDE = 2;
+    const L10NMGR_CONFIGURATION_INCLUDE = 3;
+
+}
\ No newline at end of file
index 6913c2a..ae3309f 100644 (file)
@@ -18,13 +18,15 @@ namespace Localizationteam\L10nmgr\Model;
  * GNU General Public License for more details.
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
+use Localizationteam\L10nmgr\Constants;
 use Localizationteam\L10nmgr\Model\Tools\Tools;
 use TYPO3\CMS\Backend\Tree\View\PageTreeView;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
-use TYPO3\CMS\Core\Utility\DebugUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\RootlineUtility;
 
 /**
  * l10nAccumulatedInformations
@@ -80,6 +82,14 @@ class L10nAccumulatedInformation
      * @var array Extension's configuration as from the EM
      */
     protected $extensionConfiguration = array();
+    /**
+     * @var array Index of pages to be excluded from translation
+     */
+    protected $excludeIndex = array();
+    /**
+     * @var array Index of pages to be included with translation
+     */
+    protected $includeIndex = array();
 
     /**
      * Constructor
@@ -142,7 +152,7 @@ class L10nAccumulatedInformation
         // FlexForm Diff data:
         $flexFormDiff = unserialize($l10ncfg['flexformdiff']);
         $flexFormDiff = $flexFormDiff[$sysLang];
-        $excludeIndex = array_flip(GeneralUtility::trimExplode(',', $l10ncfg['exclude'], 1));
+        $this->excludeIndex = array_flip(GeneralUtility::trimExplode(',', $l10ncfg['exclude'], true));
         $tableUidConstraintIndex = array_flip(GeneralUtility::trimExplode(',', $l10ncfg['tableUidConstraint'], 1));
         // Init:
         /** @var Tools $t8Tools */
@@ -163,9 +173,30 @@ class L10nAccumulatedInformation
         }
         $fileList = '';
         // Traverse tree elements:
+        /**
+         * @var $rootlineUtility RootlineUtility
+         */
         foreach ($tree->tree as $treeElement) {
             $pageId = $treeElement['row']['uid'];
-            if (!isset($excludeIndex['pages:' . $pageId]) && !in_array($treeElement['row']['doktype'],
+            if ($treeElement['row']['l10nmgr_configuration'] === Constants::L10NMGR_CONFIGURATION_DEFAULT) {
+                $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
+                $rootline = $rootlineUtility->get();
+                if (!empty($rootline)) {
+                    foreach ($rootline as $rootlinePage) {
+                        if ($rootlinePage['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_DEFAULT) {
+                            continue;
+                        } elseif ($rootlinePage['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_NONE || $rootlinePage['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_INCLUDE) {
+                            break;
+                        } elseif ($rootlinePage['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_EXCLUDE) {
+                            $this->excludeIndex['pages:' . $pageId] = 1;
+                            break;
+                        }
+                    }
+                }
+            } elseif ($treeElement['row']['l10nmgr_configuration'] === Constants::L10NMGR_CONFIGURATION_EXCLUDE) {
+                $this->excludeIndex['pages:' . $pageId] = 1;
+            }
+            if (!isset($this->excludeIndex['pages:' . $pageId]) && !in_array($treeElement['row']['doktype'],
                     $this->disallowDoktypes)
             ) {
                 $accum[$pageId]['header']['title'] = $treeElement['row']['title'];
@@ -198,7 +229,7 @@ class L10nAccumulatedInformation
                                                 $this->_increaseInternalCounters($accum[$pageId]['items'][$table][$row['uid']]['fields']);
                                             }
                                         } else {
-                                            if (is_array($row) && !isset($excludeIndex[$table . ':' . $row['uid']])) {
+                                            if (is_array($row) && !isset($this->excludeIndex[$table . ':' . $row['uid']])) {
                                                 $accum[$pageId]['items'][$table][$row['uid']] = $t8Tools->translationDetails($table,
                                                     $row, $sysLang, $flexFormDiff, $previewLanguage);
                                                 $this->_increaseInternalCounters($accum[$pageId]['items'][$table][$row['uid']]['fields']);
@@ -210,12 +241,16 @@ class L10nAccumulatedInformation
                         }
                     }
                     if ($table === 'sys_file_reference' && !empty($fileList)) {
-                        $fileList = implode(',', array_keys(array_flip(GeneralUtility::intExplode(',', $fileList, true))));
+                        $fileList = implode(',',
+                            array_keys(array_flip(GeneralUtility::intExplode(',', $fileList, true))));
                         if (!empty($fileList)) {
-                            $metaData = $this->getDatabaseConnection()->exec_SELECTgetRows('uid', 'sys_file_metadata', 'sys_language_uid = ' . (int)$previewLanguage . ' AND file IN (' . $fileList . ')', '', 'uid', '', 'uid');
+                            $metaData = $this->getDatabaseConnection()->exec_SELECTgetRows('uid', 'sys_file_metadata',
+                                'sys_language_uid = ' . (int)$previewLanguage . ' AND file IN (' . $fileList . ')', '',
+                                'uid', '', 'uid');
                             if (!empty($metaData)) {
                                 $l10ncfg['include'] .= $l10ncfg['include'] ? ',' : '';
-                                $l10ncfg['include'] .= 'sys_file_metadata:' . implode(',sys_file_metadata:', array_keys($metaData));
+                                $l10ncfg['include'] .= 'sys_file_metadata:' . implode(',sys_file_metadata:',
+                                        array_keys($metaData));
                             }
                         }
                     }
@@ -223,8 +258,8 @@ class L10nAccumulatedInformation
             }
         }
 
-        $includeIndex = array_unique(GeneralUtility::trimExplode(',', $l10ncfg['include'], 1));
-        foreach ($includeIndex as $recId) {
+        $this->addPagesMarkedAsIncluded($l10ncfg['include'], $l10ncfg['exclude']);
+        foreach ($this->includeIndex as $recId => $rec) {
             list($table, $uid) = explode(':', $recId);
             $row = BackendUtility::getRecordWSOL($table, $uid);
             if (count($row)) {
@@ -238,6 +273,61 @@ class L10nAccumulatedInformation
     }
 
     /**
+     * @param string $indexList
+     */
+    protected function addPagesMarkedAsIncluded($indexList, $excludeList) {
+        $this->includeIndex = array();
+        $this->excludeIndex = array_flip(GeneralUtility::trimExplode(',', $excludeList, true));
+        if ($indexList) {
+            $this->includeIndex = array_flip(GeneralUtility::trimExplode(',', $indexList, true));
+        }
+        $enableClause = BackendUtility::BEenableFields('pages');
+        $explicitlyIncludedPages = $this->getDatabaseConnection()->exec_SELECTgetRows('uid', 'pages',
+            'l10nmgr_configuration = ' . Constants::L10NMGR_CONFIGURATION_INCLUDE . $enableClause);
+        if (!empty($explicitlyIncludedPages)) {
+            foreach ($explicitlyIncludedPages as $page) {
+                if (!isset($this->excludeIndex['pages:' . $page['uid']]) && !in_array($page['doktype'],
+                        $this->disallowDoktypes)
+                ) {
+                    $this->includeIndex['pages:' . $page['uid']] = 1;
+                }
+            }
+        }
+        $includingParentPages = $this->getDatabaseConnection()->exec_SELECTgetRows('uid', 'pages',
+            'l10nmgr_configuration_next_level = ' . Constants::L10NMGR_CONFIGURATION_INCLUDE . $enableClause);
+        if (!empty($includingParentPages)) {
+            foreach ($includingParentPages as $parentPage) {
+                $this->addSubPagesRecursively($parentPage['uid']);
+            }
+        }
+    }
+
+    /**
+     * Walks through a tree branch and checks if pages are to be included
+     * Will ignore pages with explicit l10nmgr_configuration settings but still walk through their subpages
+     * @param int $uid
+     * @param int $level
+     */
+    protected function addSubPagesRecursively($uid, $level = 0) {
+        $level ++;
+        if ($uid > 0 && $level < 100) {
+            $enableClause = BackendUtility::BEenableFields('pages');
+            $subPages = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,pid,l10nmgr_configuration,l10nmgr_configuration_next_level', 'pages',
+                'pid = ' . (int)$uid . $enableClause);
+            if (!empty($subPages)) {
+                foreach ($subPages as $page) {
+                    if ($page['l10nmgr_configuration'] === Constants::L10NMGR_CONFIGURATION_DEFAULT) {
+                        $this->includeIndex['pages:' . $page['uid']] = 1;
+                    }
+                    if ($page['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_DEFAULT || $page['l10nmgr_configuration_next_level'] === Constants::L10NMGR_CONFIGURATION_INCLUDE) {
+                        $this->addSubPagesRecursively($page['uid'], $level);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * Returns the Backend User
      * @return BackendUserAuthentication
      */
diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php
new file mode 100644 (file)
index 0000000..39a1136
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', [
+    'l10nmgr_configuration' => [
+        'exclude' => 1,
+        'label' => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration',
+        'config' => [
+            'type' => 'select',
+            'items' => [
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_NONE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_NONE
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_EXCLUDE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_EXCLUDE
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_INCLUDE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_INCLUDE
+                ]
+            ],
+            'default' => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT
+        ]
+    ],
+    'l10nmgr_configuration_next_level' => [
+        'exclude' => 1,
+        'label' => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration_next_level',
+        'config' => [
+            'type' => 'select',
+            'items' => [
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_NONE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_NONE
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_EXCLUDE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_EXCLUDE
+                ],
+                [
+                    0 => 'LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.l10nmgr_configuration.I.' . \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_INCLUDE,
+                    1 => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_INCLUDE
+                ],
+            ],
+            'default' => \Localizationteam\L10nmgr\Constants::L10NMGR_CONFIGURATION_DEFAULT
+        ]
+    ]
+]);
+
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('pages', 'l10nmgr_configuration', 'l10nmgr_configuration,l10nmgr_configuration_next_level');
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages', '--palette--;LLL:EXT:l10nmgr/Resources/Private/Language/locallang_db.xlf:pages.palettes.l10nmgr_configuration;l10nmgr_configuration', '', 'after:l18n_cfg');
index 465f0df..ac6ed29 100644 (file)
                        <trans-unit id="tx_l10nmgr_priorities.element" xml:space="preserve">
                                <source>Element(s):</source>
                        </trans-unit>
+
+                       <trans-unit id="pages.palettes.l10nmgr_configuration" xml:space="preserve">
+                               <source>Additional Localization Manager Settings (might be overriden by l10nmgr configuration)</source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration" xml:space="preserve">
+                               <source>Translation settings (this page only)</source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration_next_level" xml:space="preserve">
+                               <source>Translation settings (subpages of this page)</source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration.I.0" xml:space="preserve">
+                               <source></source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration.I.1" xml:space="preserve">
+                               <source>None (resets subpage settings from rootline)</source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration.I.2" xml:space="preserve">
+                               <source>Exclude from translations</source>
+                       </trans-unit>
+                       <trans-unit id="pages.l10nmgr_configuration.I.3" xml:space="preserve">
+                               <source>Always include within translations (overrides exclude)</source>
+                       </trans-unit>
         </body>
     </file>
 </xliff>
\ No newline at end of file
index 2b9a9a6..6b30105 100644 (file)
@@ -33,3 +33,5 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Localizationtea
     'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/Task/locallang.xlf:fileGarbageCollection.description',
     'additionalFields' => 'LocalizationmanagerFileGarbageCollectionAdditionalFieldProvider',
 );
+
+$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] .= ',l10nmgr_configuration,l10nmgr_configuration_next_level';
index ceaac2c..5964746 100644 (file)
@@ -92,3 +92,11 @@ CREATE TABLE tx_l10nmgr_exportdata (
        
        PRIMARY KEY (uid),
 );
+
+#
+# Table structure for table 'pages'
+#
+CREATE TABLE pages (
+       l10nmgr_configuration tinyint(4) DEFAULT '0' NOT NULL,
+       l10nmgr_configuration_next_level tinyint(4) DEFAULT '0' NOT NULL,
+);