diff --git a/typo3/sysext/linkvalidator/Documentation/Configuration/Index.rst b/typo3/sysext/linkvalidator/Documentation/Configuration/Index.rst index 7e23dfd40fed5bdabb30cddb723a11347a248792..f50335342e324d1a6058c82010bb5b47f1bd9563 100644 --- a/typo3/sysext/linkvalidator/Documentation/Configuration/Index.rst +++ b/typo3/sysext/linkvalidator/Documentation/Configuration/Index.rst @@ -132,7 +132,7 @@ linktypes db,file,external - +.. _linktypes-config: .. _linktypes-config-external: linktypesConfig.external.httpAgentName diff --git a/typo3/sysext/linkvalidator/Documentation/Development/LinkTypeImplementation.rst b/typo3/sysext/linkvalidator/Documentation/Development/LinkTypeImplementation.rst index 30ce37bc435af37f6bc1453c3f945bfb93b050e5..c2361fc615f6ef8c43811128cb089dc7d8476d93 100644 --- a/typo3/sysext/linkvalidator/Documentation/Development/LinkTypeImplementation.rst +++ b/typo3/sysext/linkvalidator/Documentation/Development/LinkTypeImplementation.rst @@ -34,6 +34,9 @@ it is sufficient to set the :php:`$identifier` class property. Example ======= +Add new linktype +---------------- + You can find the following example in the extension `t3docs/examples <https://github.com/TYPO3-Documentation/t3docs-examples>`__. @@ -66,6 +69,71 @@ Or if autoconfiguration is not desired for some reason: tags: - name: linkvalidator.linktype +.. _linktype-implementation-override-external: + +Override the ExternalLinktype class +----------------------------------- + +A new custom class should replace +:php:`\TYPO3\CMS\Linkvalidator\Linktype\ExternalLinktype`. The class inherits +existing functionality from :php:`ExternalLinktype`, but will be registered with +the identifier "custom_external": + +.. code-block:: php + :caption: EXT:my_extension/Classes/Linktype/ExternalLinktype.php + + namespace MyVendor\NyExtension\Linktype\ExternalLinktype; + + use TYPO3\CMS\Linkvalidator\Linktype\ExternalLinktype as LinkvalidatorExternalLinkType; + + // This class inherits from ExternalLinktype, + // so it is only necessary to override some methods. + class ExternalLinktype extends LinkvalidatorExternalLinkType + { + // This class must use a different identifier because "external" is already used. + protected string $identifier = 'custom_external'; + + public function checkLink( + string $origUrl, + array $softRefEntry, + LinkAnalyzer $reference + ): bool { + // do additional stuff here or after parent::checkLink + // ... + return parent::checkLink($origUrl, $softRefEntry, $reference); + } + + public function fetchType(array $value, string $type, string $key): string + { + preg_match_all( + '/((?:http|https))(?::\\/\\/)(?:[^\\s<>]+)/i', + (string)$value['tokenValue'], + $urls, + PREG_PATTERN_ORDER + ); + if (!empty($urls[0][0])) { + $type = $this->getIdentifier(); + } + return $type; + } + } + +Use the new linktype: + +.. code-block:: typoscript + :caption: EXT:my_extension/Configuration/page.tsconfig + + mod.linkvalidator.linktypes = db,file,custom_external + +Since the identifier changes, the configuration should be copied to +:typoscript:`mod.linkvalidator.linktypesConfig.custom_external`, so that it will be +passed to the linktype, for example: + +.. code-block:: typoscript + :caption: EXT:my_extension/Configuration/page.tsconfig + + mod.linkvalidator.linktypesConfig.custom_external < mod.linkvalidator.linktypesConfig.external + Migration from TYPO3 11 LTS and below ===================================== diff --git a/typo3/sysext/linkvalidator/Documentation/KnownProblems/Index.rst b/typo3/sysext/linkvalidator/Documentation/KnownProblems/Index.rst index 73637ad1eaad3314a10845280d47a1ad56bb2427..b6333fbe22a34fc60d6b040fc322da02db5f3b50 100644 --- a/typo3/sysext/linkvalidator/Documentation/KnownProblems/Index.rst +++ b/typo3/sysext/linkvalidator/Documentation/KnownProblems/Index.rst @@ -22,7 +22,7 @@ There are (at least) 2 possible counter-measures: #. Turn off external link checking entirely by removing `external` from Page TSconfig :ref:`linktypes` -#. :ref:`Override the ExternalLinktype class <linktype-implementation>` +#. :ref:`linktype-implementation-override-external` (in your own extension), to check only specific URLs or exclude specific URLs or handle only specific error types as errors.