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] Allow custom linktype labels in EXT:linkvalidator #1041

Open
TYPO3IncTeam opened this issue Sep 13, 2024 · 0 comments
Open

[FEATURE] Allow custom linktype labels in EXT:linkvalidator #1041

TYPO3IncTeam opened this issue Sep 13, 2024 · 0 comments
Labels

Comments

@TYPO3IncTeam
Copy link
Collaborator

ℹ️ View this commit on Github
👥 Authored by Sybille Peters [email protected]
✔️ Merged by Stefan Bürk [email protected]

Commit message

[FEATURE] Allow custom linktype labels in EXT:linkvalidator

If a custom linktype is registered for the Linkvalidator, it is now
possible to define the label which will be displayed in the
backend module.

A new interface LabelledLinktypeInterface provides a method
getReadableName() to return the custom label. It is implemented
by default in the AbstractLinktype class, so any custom
linktype extending from this will be able to override the method.

When no abstract class is extended, compositing a class
with the LabelledLinktypeInterface implementation is possible.

Resolves: #103090
Releases: main
Change-Id: I8255aca6529d104be19c8af2b7cd505cd8749d7d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82876
Tested-by: core-ci [email protected]
Reviewed-by: Garvin Hicking [email protected]
Tested-by: Stefan Bürk [email protected]
Reviewed-by: Stefan Bürk [email protected]
Tested-by: Garvin Hicking [email protected]

➕ Added files

13.3/Feature-103090-MakeLinktypeLabelConfigurable.rst
.. include:: /Includes.rst.txt

.. _feature-103090-1707479280:

===================================================
Feature: #103090 - Make linktype label configurable
===================================================

See :issue:`103090`

Description
===========

It is now possible to provide a translated label for custom linktypes.

For this, a new interface
:php:`\TYPO3\CMS\Linkvalidator\Linktype\LabelledLinktypeInterface` has been
created, which offers the method :php:`getReadableName` for implementation.
That method can return the translated label.

The default abstract implementation
:php:`\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype` has been enhanced
to implement that interface. Any custom class extending this abstract is
able to override the method :php:`getReadableName` to provide the
custom translation.

Example extending the abstract:
-------------------------------

..  code-block:: php
    :caption: EXT:extension/Classes/Linktype/CustomLinktype.php

    use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;

    #[Autoconfigure(public: true)]
    class CustomLinktype extends AbstractLinktype
    {
        public function getReadableName(): string
        {
            $type = $this->getIdentifier();
            return $this->getLanguageService()->sL(
                'LLL:EXT:linkvalidator_example/Resources/Private/Language/Module/locallang.xlf:linktype_'
                . $type
            ) ?: $type;
        }
    }

Example implementing the interface:
-----------------------------------

..  code-block:: php
    :caption: EXT:extension/Classes/Linktype/CustomLinktype.php

    use TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface;
    use TYPO3\CMS\Linkvalidator\Linktype\LabelledLinktypeInterface;

    #[Autoconfigure(public: true)]
    class CustomLinktype implements LinktypeInterface, LabelledLinktypeInterface
    {
        // implement all LinktypeInterface methods:
        // getIdentifier, checkLink, setAdditionalConfig, ...

        // Implement the LabelledLinktypeInterface method getReadableName()
        public function getReadableName(): string
        {
            $type = $this->getIdentifier();
            return $this->getLanguageService()->sL(
                'LLL:EXT:linkvalidator_example/Resources/Private/Language/Module/locallang.xlf:linktype_'
                . $type
            ) ?: $type;
        }
    }

Impact
======

Custom linktype classes should now configure a label by implementing the method
:php:`LabelledLinktypeInterface::getReadableName()`.

All existing custom implementations of the `AbstractLinktype` class or the `LinktypeInterface`
will continue to work as before, and will just continue to use the internal name of
the linktype, instead of a translated label.


.. index:: Backend, ext:linkvalidator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant