BrokenLinkAnalysisEvent

The PSR-14 event \TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent can be used to get information about broken links set in the rich text editor (RTE).

The procedure for marking the broken links in the RTE is as follow:

  1. The RTE content is fetched from the database. Before it is displayed in the edit form, RTE transformations are performed.
  2. The transformation function parses the text and detects links.
  3. For each link, a new PSR-14 event is dispatched.
  4. If a listener is attached, it may set the link as broken and will set the link as "checked".
  5. If a link is detected as broken, RTE will mark it as broken.

This functionality is implemented in the system extension linkvalidator. Other extensions can use the event to override the default behaviour.

Example

An event listener class is constructed which will take a RTE input TYPO3 and internally store it in the database as [tag:typo3]. This could allow a content element data processor in the frontend to handle this part of the content with for example internal glossary operations.

The workflow would be:

  • Editor enters "TYPO3" in the RTE instance.
  • When saving, this gets stored as "[tag:typo3]".
  • When the editor sees the RTE instance again, "[tag:typo3]" gets replaced to "TYPO3" again.
  • So: The editor will always only see "TYPO3" and not know how it is internally handled.
  • The frontend output receives "[tag:typo3]" and could do its own content element magic, other services accessing the database could also use the parseable representation.

The corresponding event listener class:

<?php

declare(strict_types=1);

namespace MyVendorMyExtensionEventListener;

use TYPO3CMSCoreAttributeAsEventListener; use TYPO3CMSCoreHtmlEventAfterTransformTextForPersistenceEvent; use TYPO3CMSCoreHtmlEventAfterTransformTextForRichTextEditorEvent;

class TransformListener { /** Transforms the current value the RTE delivered into a value that is stored (persisted) in the database. / #[AsEventListener('rtehtmlparser/modify-data-for-persistence')] public function modifyPersistence(AfterTransformTextForPersistenceEvent $event): void { $value = $event->getHtmlContent(); $value = str_replace('TYPO3', '[tag:typo3]', $value); $event->setHtmlContent($value); }

/**
  • Transforms the current persisted value into something the RTE can display

*/

#[AsEventListener('rtehtmlparser/modify-data-for-richtexteditor')] public function modifyRichTextEditor(AfterTransformTextForRichTextEditorEvent $event): void { $value = $event->getHtmlContent(); $value = str_replace('[tag:typo3]', 'TYPO3', $value); $event->setHtmlContent($value); }

}

API

class BrokenLinkAnalysisEvent
Fully qualified name
\TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent

Event that is fired to validate if a link is valid or not.

isPropagationStopped ( )
Returns
bool
getLinkType ( )

Returns the link type as string

Returns
string
getLinkData ( )

Returns resolved LinkService data, depending on the type

Returns
array
param $reason

the reason, default: ''

Returns
bool
getReason ( )
Returns
string