---
title: "Implementation of a custom linktype for the link validator"
manual: "Link Validator"
version: "main"
permalink: "https://docs.typo3.org/permalink/typo3/cms-linkvalidator:linktype-implementation@main"
source: "Development/LinkTypeImplementation.rst"
rendered: "2026-09-25T23:18:14+00:00"
---

# Implementation of a custom linktype for the link validator {#linktype-implementation}

The LinkValidator uses so called "linktypes" to check for different types of
links, for example internal or external links.

All "linktypes" have to implement the
`\TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface`.

Classes implementing the `\TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface` are automatically
registered, if [autoconfigure](https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html#dependency-injection-autoconfigure)
is enabled in `packages/my_extension/Configuration/Services.yaml`.

Alternatively, one can manually tag a custom link type with the
`linkvalidator.linktype` tag:

**packages/my_extension/Configuration/Services.yaml**

```yaml
# Other definitions

MyVendor\MyExtension\Linktype\MyCustomLinktype:
  tags:
    - name: linkvalidator.linktype

```

Due to the autoconfiguration, the identifier has to be provided by the
class directly, using the method `getIdentifier()`.

When extending `\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype`
it is sufficient to set the `$identifier` class property.

For custom naming of a linktype, the additional interface
`\TYPO3\CMS\Linkvalidator\Linktype\LabelledLinktypeInterface`.
can be implemented, which is also part of the default
`\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype` implementation.

The method `LabelledLinktypeInterface->getReadableName()` is used to
return the custom localized name of a linktype.

## Example {#linktype-implementation-example}

### Add new linktype {#linktype-implementation-example-add-link-type}

You can find the following example in the extension
[t3docs/examples](https://github.com/TYPO3-Documentation/t3docs-examples).

Extend `\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype` to create
a custom linktype:

**EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php**

```php
<?php

/*
 * This file is part of the TYPO3 CMS project. [...]
 */

namespace T3docs\Examples\LinkValidator\LinkType;

use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;

/**
 * This class provides Check Example Links plugin implementation
 */
class ExampleLinkType extends AbstractLinktype
{
    protected string $identifier = 'example';

    public function checkLink($url, $softRefEntry, $reference): bool
    {
        $isValidUrl = false;
        // TODO: Implement checkLink() method.
        return $isValidUrl;
    }

    public function getErrorMessage($errorParams): string
    {
        $lang = $this->getLanguageService();
        return match ($errorParams['errno'] ?? 0) {
            404 => $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf:list.report.pagenotfound404'),
            // fall back to generic error message
            default => sprintf(
                $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf:list.report.externalerror'),
                $errorParams['errno'],
            ),
        };
    }
}
```

Activate the new linktype in the page tsconfig:

**EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig**

```typoscript
mod.linkvalidator {
   # specify link types to be crawled
   linktypes = db,file,external,example
}
```

The extension that provides the linktype must have a
`Configuration/Services.yaml` file that contains either:

**packages/my_extension/Configuration/Services.yaml**

```yaml
services:
  _defaults:
    autoconfigure: true

```

Or if autoconfiguration is not desired for some reason:

**packages/my_extension/Configuration/Services.yaml**

```yaml
services:
  MyVendor\MyExtension\LinkValidator\LinkType\ExampleLinkType:
    tags:
      -  name: linkvalidator.linktype

```

### Override the ExternalLinktype class {#linktype-implementation-override-external}

A new custom class should replace
`\TYPO3\CMS\Linkvalidator\Linktype\ExternalLinktype`. The class inherits
existing functionality from `ExternalLinktype`, but will be registered with
the identifier "custom_external":

**packages/my_extension/Classes/Linktype/ExternalLinktype.php**

```php
<?php

namespace MyVendor\NyExtension\Linktype\ExternalLinktype;

use TYPO3\CMS\Linkvalidator\LinkAnalyzer;
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:

**packages/my_extension/Configuration/page.tsconfig**

```typoscript
mod.linkvalidator.linktypes = db,file,custom_external
```

Since the identifier changes, the configuration should be copied to
`mod.linkvalidator.linktypesConfig.custom_external`, so that it will be
passed to the linktype, for example:

**packages/my_extension/Configuration/page.tsconfig**

```typoscript
mod.linkvalidator.linktypesConfig.custom_external < mod.linkvalidator.linktypesConfig.external
```
