Skip to content

Commit

Permalink
[TASK] Deprecate PageRepository->getExtURL()
Browse files Browse the repository at this point in the history
PageRepository->getExtURL() is a pretty upgly
public helper method that has a depedency to
$GLOBALS['TYPO3_REQUEST']. It is used only once.
The patch moves the method body to the consuming
class and deprecates it.

Resolves: #99558
Releases: main
Change-Id: I7c1e8d6b1a454950de6fa7469d13fbab81ee2962
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77330
Reviewed-by: Jasmina Ließmann <minapokhalo+typo3@gmail.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Jasmina Ließmann <minapokhalo+typo3@gmail.com>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
bmack authored and o-ba committed Jan 16, 2023
1 parent e03aa6d commit 4818ef2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
30 changes: 26 additions & 4 deletions typo3/sysext/backend/Classes/Controller/PageLayoutController.php
Expand Up @@ -139,7 +139,7 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
$view->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
$view->assignMultiple([
'pageId' => $this->id,
'infoBoxes' => $this->generateMessagesForCurrentPage(),
'infoBoxes' => $this->generateMessagesForCurrentPage($request),
'isPageEditable' => $this->isPageEditable($this->currentSelectedLanguage),
'localizedPageTitle' => $this->getLocalizedPageTitle($this->currentSelectedLanguage, $this->pageinfo),
'eventContentHtmlTop' => $event->getHeaderContent(),
Expand Down Expand Up @@ -341,7 +341,7 @@ protected function makeActionMenu(ModuleTemplate $view, array $tsConfig): void
* Return an array of various messages for the current page record,
* such as if the page has a special doktype, that can be rendered as info boxes.
*/
protected function generateMessagesForCurrentPage(): array
protected function generateMessagesForCurrentPage(ServerRequestInterface $request): array
{
$languageService = $this->getLanguageService();
$backendUser = $this->getBackendUser();
Expand Down Expand Up @@ -420,8 +420,8 @@ protected function generateMessagesForCurrentPage(): array
'state' => InfoboxViewHelper::STATE_ERROR,
];
} else {
$externalUrl = $this->pageRepository->getExtURL($this->pageinfo);
if (is_string($externalUrl)) {
$externalUrl = $this->resolveExternalUrl($this->pageinfo, $request);
if ($externalUrl !== '') {
$externalUrl = htmlspecialchars($externalUrl);
$externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noreferrer">' . $externalUrl . '</a>';
$infoBoxes[] = [
Expand Down Expand Up @@ -822,6 +822,28 @@ protected function getShortcutTitle(): string
);
}

/**
* Returns the redirect URL for the input page row IF the doktype is set to 3.
*/
protected function resolveExternalUrl(array $pagerow, ServerRequestInterface $request): string
{
$redirectTo = (string)($pagerow['url'] ?? '');
if ($redirectTo === '') {
return '';
}
$urlInformation = parse_url($redirectTo);
// If relative path, prefix Site URL
// If it's a valid email without protocol, add "mailto:"
if (!($urlInformation['scheme'] ?? false)) {
if (GeneralUtility::validEmail($redirectTo)) {
$redirectTo = 'mailto:' . $redirectTo;
} elseif ($redirectTo[0] !== '/') {
$redirectTo = $request->getAttribute('normalizedParams')->getSiteUrl() . $redirectTo;
}
}
return $redirectTo;
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
Expand Down
Expand Up @@ -1130,14 +1130,17 @@ public function resolveShortcutPage(array $page, bool $resolveRandomSubpages = f

return $page;
}

/**
* Returns the redirect URL for the input page row IF the doktype is set to 3.
*
* @param array $pagerow The page row to return URL type for
* @return string|bool The URL from based on the data from "pages:url". False if not found.
* @deprecated since TYPO3 v12, will be removed in TYPO3 v13.0
*/
public function getExtURL($pagerow)
{
trigger_error('PageRepository->getExtURL will be removed in TYPO3 v13.0.', E_USER_DEPRECATED);
if ((int)$pagerow['doktype'] === self::DOKTYPE_LINK) {
$redirectTo = $pagerow['url'];
$uI = parse_url($redirectTo);
Expand Down
@@ -0,0 +1,40 @@
.. include:: /Includes.rst.txt

.. _deprecation-99558-1673887807:

===========================================================
Deprecation: #99558 - Deprecate PageRepository->getExtURL()
===========================================================

See :issue:`99558`

Description
===========

The method :php:`\TYPO3\CMS\Core\Domain\Repository\PageRepository->getExtURL()`
has been marked as deprecated and should not be used any longer.


Impact
======

Calling the method triggers a deprecation level log message since
TYPO3 v12 and will stop working in v13.


Affected installations
======================

:php:`PageRepository->getExtURL()` is a detail method and relatively unlikely
to be used by extensions. The extension scanner will find affected code places.


Migration
=========

The method has been discontinued and there is no direct migration.

If needed, the most simple solution is to copy the method to an extensions
code base and maintain it within the extension.

.. index:: Backend, PHP-API, FullyScanned, ext:core
Expand Up @@ -15,7 +15,7 @@
* The TYPO3 project - inspiring people to share!
*/

namespace TYPO3\CMS\Core\Tests\Unit\Domain\Repository;
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Domain\Repository;

use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
Expand Down
Expand Up @@ -5463,4 +5463,11 @@
'Deprecation-99531-Backwards-compatibleLanguageKeyMapping.rst',
],
],
'TYPO3\CMS\Core\Domain\Repository\PageRepository->getExtURL' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-99558-DeprecatePageRepository-getExtURL.rst',
],
],
];

0 comments on commit 4818ef2

Please sign in to comment.