Skip to content
Snippets Groups Projects
Commit 78b8e499 authored by linawolf's avatar linawolf Committed by Lina Wolf
Browse files

[DOCS] Update linkvalidator codesnippets

* Make the code-snippets auto-generatable
* Remove API for internal class
* Fix references

Attention: Backport need manual changes.

Resolves: #103317
Releases: main, 12.4
Change-Id: I79686223ee01faff9070612988a25c6f2da0e040
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83291


Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarLina Wolf <112@linawolf.de>
Tested-by: default avatarLina Wolf <112@linawolf.de>
parent f781d5d1
Branches
Tags
No related merge requests found
Showing
with 122 additions and 149 deletions
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools
.. bin/typo3 restructured_api_tools:php_domain '\\TYPO3\\CMS\\Linkvalidator\\Linktype\\AbstractLinktype' > output/AbstractLinktype.rst.txt
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. php:namespace:: TYPO3\CMS\Linkvalidator\Linktype
.. php:class:: AbstractLinktype
......@@ -8,47 +6,45 @@
This class provides Check Base plugin implementation
.. php:method:: getIdentifier()
:returntype: string
.. php:method:: setAdditionalConfig(array config)
.. php:method:: setAdditionalConfig(array $config)
Function to override config of Linktype. Should be used only
if necessary. Add additional configuration to TSconfig.
:param array $config: the config
.. php:method:: fetchType(unknown value, unknown type, unknown key)
.. php:method:: fetchType(array $value, string $type, string $key)
Base type fetching method, based on the type that softRefParserObj returns
:param unknown $value: the value
:param unknown $type: the type
:param unknown $key: the key
:param array $value: Reference properties
:param string $type: Current type
:param string $key: Validator hook name
.. php:method:: getErrorParams()
Get the value of the private property errorParams
.. php:method:: getBrokenUrl(unknown row)
.. php:method:: getBrokenUrl(array $row)
Construct a valid Url for browser output
:param unknown $row: the row
:param array $row: Broken link record
.. php:method:: checkLink(unknown url, unknown softRefEntry, unknown reference)
.. php:method:: checkLink(string $url, array $softRefEntry, \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference)
Checks a given link for validity
:param unknown $url: the url
:param unknown $softRefEntry: the softRefEntry
:param unknown $reference: the reference
:param string $url: Url to check
:param array $softRefEntry: The soft reference entry which builds the context of that url
:param \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference: Parent instance
.. php:method:: getErrorMessage(unknown errorParams)
.. php:method:: getErrorMessage(array $errorParams)
Generate the localized error message from the error params saved from the parsing
:param unknown $errorParams: the errorParams
:param array $errorParams: All parameters needed for the rendering of the error message
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools
.. php:namespace:: TYPO3\CMS\Linkvalidator\Result
.. php:class:: LinkAnalyzerResult
Used to work with LinkAnalyzer results
.. php:method:: getResultForTask(int page, int depth, array pageRow, array modTSconfig, array searchFields = array (), array linkTypes = array (), string languages = '')
Call LinkAnalyzer with provided task configuration and process result values
:param int $page: the page
:param int $depth: the depth
:param array $pageRow: the pageRow
:param array $modTSconfig: the modTSconfig
:param array $searchFields: the searchFields, default: array ()
:param array $linkTypes: the linkTypes, default: array ()
:param string $languages: the languages, default: ''
:returntype: self
.. php:method:: setBrokenLinks(array brokenLinks)
:param array $brokenLinks: the brokenLinks
.. php:method:: getBrokenLinks()
:returntype: array
.. php:method:: setNewBrokenLinkCounts(array newBrokenLinkCounts)
:param array $newBrokenLinkCounts: the newBrokenLinkCounts
.. php:method:: getNewBrokenLinkCounts()
:returntype: array
.. php:method:: setOldBrokenLinkCounts(array oldBrokenLinkCounts)
:param array $oldBrokenLinkCounts: the oldBrokenLinkCounts
.. php:method:: getOldBrokenLinkCounts()
:returntype: array
.. php:method:: getTotalBrokenLinksCount()
:returntype: int
.. php:method:: isDifferentToLastResult()
:returntype: bool
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools
.. ddev exec bin/typo3 restructured_api_tools:php_domain '\\TYPO3\\CMS\\Linkvalidator\\Linktype\\LinktypeInterface' > output/LinktypeInterface.rst.txt
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. php:namespace:: TYPO3\CMS\Linkvalidator\Linktype
.. php:interface:: LinktypeInterface
All linktypes handled by the LinkValidator must implement this interface.
If `autoconfigure` is enabled in the :file:`Services.yaml`
classes implementing this interface are registered automatically as linktypes.
Otherwise the tag `linkvalidator.linktype` must be set in the
:file:`Services.yaml`.
This class provides interface implementation.
.. php:method:: getIdentifier()
......@@ -18,43 +11,41 @@
:returntype: string
.. php:method:: checkLink(unknown url, unknown softRefEntry, unknown reference)
.. php:method:: checkLink(string $url, array $softRefEntry, \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference)
Checks a given link for validity
:param unknown $url: the url
:param unknown $softRefEntry: the softRefEntry
:param unknown $reference: the reference
:param string $url: Url to check
:param array $softRefEntry: The soft reference entry which builds the context of that url
:param \\TYPO3\\CMS\\Linkvalidator\\LinkAnalyzer $reference: Parent instance
.. php:method:: setAdditionalConfig(array config)
.. php:method:: setAdditionalConfig(array $config)
Function to override config of Linktype. Should be used only
if necessary. Add additional configuration to TSconfig.
:param array $config: the config
.. php:method:: fetchType(unknown value, unknown type, unknown key)
.. php:method:: fetchType(array $value, string $type, string $key)
Base type fetching method, based on the type that softRefParserObj returns.
:param unknown $value: the value
:param unknown $type: the type
:param unknown $key: the key
:param array $value: Reference properties
:param string $type: Current type
:param string $key: Validator hook name
.. php:method:: getErrorParams()
Get the value of the private property errorParams.
.. php:method:: getBrokenUrl(unknown row)
.. php:method:: getBrokenUrl(array $row)
Construct a valid Url for browser output
:param unknown $row: the row
:param array $row: Broken link record
.. php:method:: getErrorMessage(unknown errorParams)
.. php:method:: getErrorMessage(array $errorParams)
Generate the localized error message from the error params saved from the parsing
:param unknown $errorParams: the errorParams
:param array $errorParams: All parameters needed for the rendering of the error message
<?php
return [
// Examples
[
'action' => 'createCodeSnippet',
'caption' => 'EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php',
'sourceFile' => 'EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php',
'replaceFirstMultilineComment' => true,
'targetFileName' => 'CodeSnippets/Examples/ExampleLinkType.rst.txt',
],
[
'action' => 'createCodeSnippet',
'caption' => 'EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig',
'sourceFile' => 'EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig',
'targetFileName' => 'CodeSnippets/Examples/ActivateCustomLinktypeTsConfig.rst.txt',
'language' => 'typoscript',
],
// API
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype::class,
'targetFileName' => 'CodeSnippets/Api/AbstractLinktype.rst.txt',
'withCode' => false,
],
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface::class,
'targetFileName' => 'CodeSnippets/Api/LinktypeInterface.rst.txt',
'withCode' => false,
],
];
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. Extracted from EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig
.. code-block:: typoscript
:caption: EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.typoscript
mod.linkvalidator {
linktypes = db,file,external,example
}
:caption: EXT:examples/Configuration/TsConfig/Page/Extension/Linkvalidator.tsconfig
mod.linkvalidator {
# specify link types to be crawled
linktypes = db,file,external,example
}
\ No newline at end of file
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. Extracted from EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php
.. code-block:: php
:caption: EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.php
use TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype;
class ExampleLinkType extends AbstractLinktype
{
protected string $identifier = 'example';
public function checkLink($url, $softRefEntry, $reference)
{
$isValidUrl = false;
// TODO: Implement checkLink() method.
return $isValidUrl;
}
public function getErrorMessage($errorParams)
{
$lang = $this->getLanguageService();
switch ($errorParams['errno'] ?? 0) {
case 404:
$message = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf:list.report.pagenotfound404');
break;
default:
// fall back to generic error message
$message = sprintf($lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf:list.report.externalerror'), $errorParams['errno']);
}
return $message;
}
}
:caption: EXT:examples/Classes/LinkValidator/LinkType/ExampleLinkType.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)
{
$isValidUrl = false;
// TODO: Implement checkLink() method.
return $isValidUrl;
}
public function getErrorMessage($errorParams)
{
$lang = $this->getLanguageService();
return match ($errorParams['errno'] ?? 0) {
404 => $lang->getLL('list.report.pagenotfound404'),
// fall back to generic error message
default => sprintf($lang->getLL('list.report.externalerror'), $errorParams['errno']),
};
}
}
\ No newline at end of file
......@@ -14,6 +14,5 @@ of third party extensions. For the complete API have a look into the code.
AbstractLinktype
LinktypeInterface
LinkAnalyzerResult
BeforeRecordIsAnalyzedEvent <https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/Events/Linkvalidator/BeforeRecordIsAnalyzedEvent.html>
ModifyValidatorTaskEmailEvent <https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/Events/Linkvalidator/ModifyValidatorTaskEmailEvent.html>
.. include:: /Includes.rst.txt
.. _linkvalidatorapi-LinkAnalyzerResult:
==================
LinkAnalyzerResult
==================
The :php:`LinkAnalyzerResult` can be manipulated by the event
:ref:`TYPO3\\CMS\\Linkvalidator\\Event\\ModifyValidatorTaskEmailEvent <t3coreapi:ModifyValidatorTaskEmailEvent>`.
API
===
.. include:: /CodeSnippets/Api/LinkAnalyzerResult.rst.txt
......@@ -10,13 +10,13 @@ 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
:php:interface:`TYPO3\\CMS\\Linkvalidator\\Linktype\\LinktypeInterface`.
:ref:`\TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface <linkvalidatorapi-LinktypeInterface>`.
Classes implementing the :php:`LinktypeInterface` are automatically
registered, if :ref:`autoconfigure <t3coreapi:dependency-injection-autoconfigure>`
is enabled in :file:`Services.yaml`.
Alternatively, one can manually tag a custom "linktype" with the
Alternatively, one can manually tag a custom link type with the
:yaml:`linkvalidator.linktype` tag:
.. code-block:: yaml
......@@ -28,7 +28,7 @@ Alternatively, one can manually tag a custom "linktype" with the
Due to the autoconfiguration, the identifier has to be provided by the
class directly, using the method :php:`getIdentifier()`.
When extending :php:class:`TYPO3\\CMS\\Linkvalidator\\Linktype\\AbstractLinktype`
When extending :ref:`\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype <linkvalidatorapi-AbstractLinktype>`
it is sufficient to set the :php:`$identifier` class property.
Example
......@@ -40,7 +40,7 @@ Add new linktype
You can find the following example in the extension
`t3docs/examples <https://github.com/TYPO3-Documentation/t3docs-examples>`__.
Extend :php:class:`TYPO3\\CMS\\Linkvalidator\\Linktype\\AbstractLinktype` to create
Extend :ref:`\TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype <linkvalidatorapi-AbstractLinktype>` to create
a custom linktype:
.. include:: /CodeSnippets/Examples/ExampleLinkType.rst.txt
......
<?php
// https://github.com/TYPO3-Documentation/t3docs-codesnippets
// ddev exec .Build/vendor/bin/typo3 codesnippet:create Documentation/
return array_merge(
include ('CodeSnippets/Config/All.php'),
);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment