Skip to content

Commit

Permalink
[TASK] Disable slug in pseudo sites and disable alias in sites
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lolli42 authored and bmack committed Aug 30, 2018
1 parent 51a7bb5 commit 0f5d7f2
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
Expand Up @@ -62,7 +62,7 @@ public function render()
$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'];
Expand Down
@@ -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;
}
}
8 changes: 7 additions & 1 deletion typo3/sysext/core/Configuration/TCA/pages.php
Expand Up @@ -154,6 +154,7 @@
'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' => [
Expand Down Expand Up @@ -434,7 +435,12 @@
],
'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' => [
Expand Down

0 comments on commit 0f5d7f2

Please sign in to comment.