Skip to content

Commit 9b68de8

Browse files
committed
[FEATURE] Support for TypolinkParameter objects in TYPO3 v13
1 parent a529e86 commit 9b68de8

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Classes/Domain/Model/Typolink.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
use SMS\FluidComponents\Exception\InvalidArgumentException;
77
use SMS\FluidComponents\Interfaces\ConstructibleFromArray;
88
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
9+
use SMS\FluidComponents\Interfaces\ConstructibleFromTypolinkParameter;
910
use TYPO3\CMS\Core\LinkHandling\LinkService;
1011
use TYPO3\CMS\Core\LinkHandling\TypoLinkCodecService;
12+
use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;
1113
use TYPO3\CMS\Core\Utility\GeneralUtility;
1214
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1315

1416
/**
1517
* Data Structure to provide information extracted from a Typolink string
1618
* in a structured matter.
1719
*/
18-
class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray
20+
class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray, ConstructibleFromTypolinkParameter
1921
{
2022
/**
2123
* Data interpretation of the provided TYPO3 uri.
@@ -116,6 +118,31 @@ public static function fromArray(array $typolinkData): self
116118
return $instance;
117119
}
118120

121+
public static function fromTypolinkParameter(TypolinkParameter $parameter): self
122+
{
123+
// Analyze structure of provided TYPO3 uri
124+
$linkService = GeneralUtility::makeInstance(LinkService::class);
125+
$uriStructure = $linkService->resolve($parameter->url);
126+
127+
// Generate general purpose uri (https://) from TYPO3 uri (t3://)
128+
// Could also be a mailto or tel uri
129+
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
130+
$uri = $cObj->typoLink_URL([
131+
'parameter' => $parameter->url,
132+
'additionalParams' => $parameter->additionalParams,
133+
]);
134+
135+
// TODO constructor code should be avoided in the future, but this would require changes
136+
// to the current constructure method signature (such as making the string nullable),
137+
// which would be a breaking change.
138+
return (new static(''))
139+
->setUri($uri)
140+
->setOriginalLink($uriStructure)
141+
->setTarget($parameter->target)
142+
->setClass($parameter->class)
143+
->setTitle($parameter->title);
144+
}
145+
119146
public function setOriginalLink(array $originalLink): self
120147
{
121148
$this->originalLink = $originalLink;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SMS\FluidComponents\Interfaces;
4+
5+
use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;
6+
7+
/**
8+
* ConstructibleFromTypolinkParameter defines an alternative constructor
9+
* which "converts" the provided ConstructibleFromTypolinkParameter instance
10+
* to the class implementing the interface.
11+
*/
12+
interface ConstructibleFromTypolinkParameter
13+
{
14+
/**
15+
* Creates an instance of the class based on the provided object.
16+
*/
17+
public static function fromTypolinkParameter(TypolinkParameter $value): object;
18+
}

Classes/Utility/ComponentArgumentConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
1414
use SMS\FluidComponents\Interfaces\ConstructibleFromNull;
1515
use SMS\FluidComponents\Interfaces\ConstructibleFromString;
16+
use SMS\FluidComponents\Interfaces\ConstructibleFromTypolinkParameter;
1617
use Traversable;
18+
use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;
1719
use TYPO3\CMS\Core\Resource\AbstractFile;
1820
use TYPO3\CMS\Core\Resource\FileInterface;
1921
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
@@ -66,6 +68,10 @@ class ComponentArgumentConverter implements \TYPO3\CMS\Core\SingletonInterface
6668
ConstructibleFromFileInterface::class,
6769
'fromFileInterface',
6870
],
71+
TypolinkParameter::class => [
72+
ConstructibleFromTypolinkParameter::class,
73+
'fromTypolinkParameter',
74+
],
6975
];
7076

7177
/**

0 commit comments

Comments
 (0)