-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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]>
- Loading branch information
Showing
11 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...e/Documentation/Changelog/13.3/Feature-103090-MakeLinktypeLabelConfigurable.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.. 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
typo3/sysext/linkvalidator/Classes/Linktype/LabelledLinktypeInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Linkvalidator\Linktype; | ||
|
||
/** | ||
* This class is used for composition in addition to LinktypeInterface, | ||
* and provides the ability to expand implementing classes with the possibility | ||
* to provide a custom Linktype label. It is utilized in the abstract class | ||
* `AbstractLinktype`. | ||
*/ | ||
interface LabelledLinktypeInterface | ||
{ | ||
/** | ||
* Get localized label for this Linktype to be displayed in Backend user interface. | ||
* Implementing classes should implement this method. | ||
*/ | ||
public function getReadableName(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../linkvalidator/Documentation/CodeSnippets/Api/LabelledLinktypeInterface.rst.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets | ||
.. php:namespace:: TYPO3\CMS\Linkvalidator\Linktype | ||
.. php:interface:: LabelledLinktypeInterface | ||
This class provides interface implementation. | ||
This class is used for composition in addition to LinktypeInterface, | ||
and provides the ability to expand implementing classes with the possibility | ||
to provide a custom Linktype label. It is utilized in the abstract class | ||
`AbstractLinktype`. | ||
|
||
.. php:method:: getReadableName() | ||
Get localized label for this linktype to be displayed in Backend user interface. | ||
Custom Linktypes should override this and provide language labels for their type. | ||
|
||
:returntype: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ysext/linkvalidator/Documentation/Development/Api/LabelledLinktypeInterface.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.. include:: /Includes.rst.txt | ||
|
||
.. _linkvalidatorapi-LabelledLinktypeInterface: | ||
|
||
========================= | ||
LabelledLinktypeInterface | ||
========================= | ||
|
||
.. include:: /CodeSnippets/Api/LabelledLinktypeInterface.rst.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters