[TASK] Disable slug in pseudo sites and disable alias in sites 13/58013/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 23 Aug 2018 20:50:44 +0000 (22:50 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 30 Aug 2018 05:43:54 +0000 (07:43 +0200)
Slug handling does now work if using pseudo sites. The patch adds
a display condition to form engine to hide the field if the edited
page is within page tree that resolves to a pseudo site.

Additionally, the 'alias' pages db field is a poor-man redirect
solution that should be outphased in v9. It is currently not resolved
if using configured sites at all. The patch turns the display condition
around for that to hide the field if a page that resolves to a proper
site object is edited.

A change in InputSlugElement that leads to wrongly resolved
languages if editing pages is fixed along the way.

Resolves: #85955
Releases: master
Change-Id: I9cc65331beb5f00edffffbe78ffcc8b50550a645
Reviewed-on: https://review.typo3.org/58013
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/Element/InputSlugElement.php
typo3/sysext/core/Classes/Compatibility/PseudoSiteTcaDisplayCondition.php [new file with mode: 0644]
typo3/sysext/core/Configuration/TCA/pages.php

index 7cd49b3..384ffd4 100644 (file)
@@ -62,7 +62,7 @@ class InputSlugElement extends AbstractFormElement
         $resultArray = $this->initializeResultArray();
 
         $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
-        $languageId = (int)($row[$languageField] ?? $this->data['defaultLanguageRow'][$languageField] ?? 0);
+        $languageId = (int)($row[$languageField][0] ?? 0);
         $baseUrl = $this->getPrefix($this->data['site'], $languageId);
 
         $itemValue = $parameterArray['itemFormElValue'];
diff --git a/typo3/sysext/core/Classes/Compatibility/PseudoSiteTcaDisplayCondition.php b/typo3/sysext/core/Classes/Compatibility/PseudoSiteTcaDisplayCondition.php
new file mode 100644 (file)
index 0000000..dadb50c
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Compatibility;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Routing\SiteMatcher;
+use TYPO3\CMS\Core\Site\Entity\Site;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * A display condition that returns true if the page we are dealing
+ * with is in a page tree that is represented by a PseudoSite object.
+ *
+ * This is used to suppress the 'slug' field in pseudo site page trees
+ * when editing page records and to show the alias field.
+ *
+ * Both "Pseudo sites" and "alias" db field will bite the dust in v10,
+ * so this is a temporary display condition for v9 only and thus marked internal.
+ *
+ * @internal Implementation and class will probably vanish in v10 without further notice
+ */
+class PseudoSiteTcaDisplayCondition
+{
+    /**
+     * Takes the given page id of the record and verifies if the page has
+     * a pseudo site object or a site object attached.
+     *
+     * @param array $parameters
+     * @return bool
+     * @throws \InvalidArgumentException
+     */
+    public function isInPseudoSite(array $parameters): bool
+    {
+        if (!isset($parameters['conditionParameters'][0])
+            || $parameters['conditionParameters'][0] !== 'pages'
+            || !isset($parameters['conditionParameters'][1])
+            || (!in_array($parameters['conditionParameters'][1], ['true', 'false'], true))
+            || empty($parameters['record']['uid'])
+        ) {
+            // Validate arguments
+            throw new \InvalidArgumentException(
+                'Invalid arguments using isInPseudoSite display condition',
+                1535055415
+            );
+        }
+
+        $defaultLanguagePageId = (int)$parameters['record']['uid'];
+        if (!empty($parameters['record']['l10n_parent'][0])) {
+            $defaultLanguagePageId = (int)$parameters['record']['l10n_parent'][0];
+        }
+
+        // Catch all: If not a "Site" object, it must be a PseudoSite or NullSite or whatever
+        // we may have invented. To be as robust as possible we just say "yes pseudo" here.
+        $isInPseudoSite = true;
+        $site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId($defaultLanguagePageId);
+        if ($site instanceof Site) {
+            $isInPseudoSite = false;
+        }
+
+        if ($parameters['conditionParameters'][1] === 'false') {
+            // Negate if requested
+            return !$isInPseudoSite;
+        }
+
+        return $isInPseudoSite;
+    }
+}
index 5c75881..508f7fa 100644 (file)
@@ -154,6 +154,7 @@ return [
         'slug' => [
             'exclude' => true,
             'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:pages.slug',
+            'displayCond' => 'USER:' . \TYPO3\CMS\Core\Compatibility\PseudoSiteTcaDisplayCondition::class . '->isInPseudoSite:pages:false',
             'config' => [
                 'type' => 'slug',
                 'generatorOptions' => [
@@ -434,7 +435,12 @@ return [
         ],
         'alias' => [
             'exclude' => true,
-            'displayCond' => 'VERSION:IS:false',
+            'displayCond' => [
+                'AND' => [
+                    'VERSION:IS:false',
+                    'USER:' . \TYPO3\CMS\Core\Compatibility\PseudoSiteTcaDisplayCondition::class . '->isInPseudoSite:pages:true',
+                ],
+            ],
             'l10n_mode' => 'exclude',
             'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.alias',
             'config' => [