|
6 | 6 | use SMS\FluidComponents\Exception\InvalidArgumentException;
|
7 | 7 | use SMS\FluidComponents\Interfaces\ConstructibleFromArray;
|
8 | 8 | use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
|
| 9 | +use SMS\FluidComponents\Interfaces\ConstructibleFromTypolinkParameter; |
9 | 10 | use TYPO3\CMS\Core\LinkHandling\LinkService;
|
10 | 11 | use TYPO3\CMS\Core\LinkHandling\TypoLinkCodecService;
|
| 12 | +use TYPO3\CMS\Core\LinkHandling\TypolinkParameter; |
11 | 13 | use TYPO3\CMS\Core\Utility\GeneralUtility;
|
12 | 14 | use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
13 | 15 |
|
14 | 16 | /**
|
15 | 17 | * Data Structure to provide information extracted from a Typolink string
|
16 | 18 | * in a structured matter.
|
17 | 19 | */
|
18 |
| -class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray |
| 20 | +class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray, ConstructibleFromTypolinkParameter |
19 | 21 | {
|
20 | 22 | /**
|
21 | 23 | * Data interpretation of the provided TYPO3 uri.
|
@@ -116,6 +118,31 @@ public static function fromArray(array $typolinkData): self
|
116 | 118 | return $instance;
|
117 | 119 | }
|
118 | 120 |
|
| 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 | + |
119 | 146 | public function setOriginalLink(array $originalLink): self
|
120 | 147 | {
|
121 | 148 | $this->originalLink = $originalLink;
|
|
0 commit comments