Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Support for TypolinkParameter objects in TYPO3 v13 #165

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
php-versions: ['8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']
typo3-versions: ['13.4', '12.4']
composer-requirements: ['Min', 'Max']
exclude:
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
php-versions: ['8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']
typo3-versions: ['13.4', '12.4']
composer-requirements: ['Min', 'Max']
exclude:
Expand Down
29 changes: 28 additions & 1 deletion Classes/Domain/Model/Typolink.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
use SMS\FluidComponents\Exception\InvalidArgumentException;
use SMS\FluidComponents\Interfaces\ConstructibleFromArray;
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
use SMS\FluidComponents\Interfaces\ConstructibleFromTypolinkParameter;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\LinkHandling\TypoLinkCodecService;
use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

/**
* Data Structure to provide information extracted from a Typolink string
* in a structured matter.
*/
class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray
class Typolink extends Link implements ConstructibleFromInteger, ConstructibleFromArray, ConstructibleFromTypolinkParameter
{
/**
* Data interpretation of the provided TYPO3 uri.
Expand Down Expand Up @@ -116,6 +118,31 @@ public static function fromArray(array $typolinkData): self
return $instance;
}

public static function fromTypolinkParameter(TypolinkParameter $parameter): self
{
// Analyze structure of provided TYPO3 uri
$linkService = GeneralUtility::makeInstance(LinkService::class);
$uriStructure = $linkService->resolve($parameter->url);

// Generate general purpose uri (https://) from TYPO3 uri (t3://)
// Could also be a mailto or tel uri
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
$uri = $cObj->typoLink_URL([
'parameter' => $parameter->url,
'additionalParams' => $parameter->additionalParams,
]);

// TODO constructor code should be avoided in the future, but this would require changes
// to the current constructor method signature (such as making the string nullable),
// which would be a breaking change.
return (new static(''))
->setUri($uri)
->setOriginalLink($uriStructure)
->setTarget($parameter->target)
->setClass($parameter->class)
->setTitle($parameter->title);
}

public function setOriginalLink(array $originalLink): self
{
$this->originalLink = $originalLink;
Expand Down
18 changes: 18 additions & 0 deletions Classes/Interfaces/ConstructibleFromTypolinkParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace SMS\FluidComponents\Interfaces;

use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;

/**
* ConstructibleFromTypolinkParameter defines an alternative constructor
* which "converts" the provided ConstructibleFromTypolinkParameter instance
* to the class implementing the interface.
*/
interface ConstructibleFromTypolinkParameter
{
/**
* Creates an instance of the class based on the provided object.
*/
public static function fromTypolinkParameter(TypolinkParameter $value): object;
}
2 changes: 1 addition & 1 deletion Classes/Service/XsdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function getDefaultPrefixForNamespace(string $namespace): int|string
*
* @return array Array of generated XML target namespaces
*/
public function generateXsd(string $path, string $namespace = null): array
public function generateXsd(string $path, ?string $namespace = null): array
{
$generatedNameSpaces = [];
$namespaces = $this->componentLoader->getNamespaces();
Expand Down
6 changes: 6 additions & 0 deletions Classes/Utility/ComponentArgumentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use SMS\FluidComponents\Interfaces\ConstructibleFromInteger;
use SMS\FluidComponents\Interfaces\ConstructibleFromNull;
use SMS\FluidComponents\Interfaces\ConstructibleFromString;
use SMS\FluidComponents\Interfaces\ConstructibleFromTypolinkParameter;
use Traversable;
use TYPO3\CMS\Core\LinkHandling\TypolinkParameter;
use TYPO3\CMS\Core\Resource\AbstractFile;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
Expand Down Expand Up @@ -66,6 +68,10 @@ class ComponentArgumentConverter implements \TYPO3\CMS\Core\SingletonInterface
ConstructibleFromFileInterface::class,
'fromFileInterface',
],
TypolinkParameter::class => [
ConstructibleFromTypolinkParameter::class,
'fromTypolinkParameter',
],
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ protected static function translateMessage(
RenderingContextInterface $renderingContext,
Message $message,
string $translatePrefix = '',
RootRenderableInterface $element = null,
string $extensionName = null,
string $languageKey = null,
array $alternativeLanguageKeys = null
?RootRenderableInterface $element = null,
?string $extensionName = null,
?string $languageKey = null,
?array $alternativeLanguageKeys = null
) {
// Make sure that messages are translated only once
$hash = spl_object_hash($message);
Expand Down Expand Up @@ -229,9 +229,9 @@ public static function translateValidationError(
int $code,
array $arguments,
string $defaultValue = '',
string $extensionName = null,
string $languageKey = null,
array $alternativeLanguageKeys = null
?string $extensionName = null,
?string $languageKey = null,
?array $alternativeLanguageKeys = null
): ?string {
if ($alternativeLanguageKeys) {
trigger_error('Calling translatedValidationResults with the argument $alternativeLanguageKeys will be removed in fluid-components 4.0', E_USER_DEPRECATED);
Expand Down