Commit 26a94bea authored by Benjamin Serfhos's avatar Benjamin Serfhos Committed by Christian Kuhn
Browse files

[FEATURE] Add signal for pre proccesing records

To determine the content that needs to be analysed in the linkvalidator,
allow external hooks/signals to adjust the variables when needed.

Resolves: #52217
Releases: master
Change-Id: Ie887852f356beb9b5e95188d309276dffd2155b8
Reviewed-on: http://review.typo3.org/24276

Reviewed-by: default avatarJesper Paardekooper <jesper.paardekooper@gmail.com>
Tested-by: default avatarJesper Paardekooper <jesper.paardekooper@gmail.com>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent e706019b
=================================================================
Feature - #52217: Signal for pre proccesing linkvalidator records
=================================================================
Description
===========
This signal allows for additional processing upon initialization of a specific record,
e.g. getting content data from plugin configuration in record.
Registering the signal: (in ext_localconf.php)
.. code-block:: php
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\TYPO3\CMS\Linkvalidator\LinkAnalyzer::class,
'beforeAnalyzeRecord',
\Vendor\Package\Slots\RecordAnalyzerSlot::class,
'beforeAnalyzeRecord'
);
..
The slot class:
.. code-block:: php
namespace Vendor\Package\Slots;
use TYPO3\CMS\Linkvalidator\LinkAnalyzer;
class RecordAnalyzerSlot {
/**
* Receives a signal before the record is analyzed
*
* @param array $results Array of broken links
* @param array $record Record to analyse
* @param string $table Table name of the record
* @param array $fields Array of fields to analyze
* @param LinkAnalyzer $parentObject Parent object
* @return array
*/
public function beforeAnalyzeRecord($results, $record, $table, $fields, LinkAnalyzer $parentObject) {
// Processing here
return array(
$results,
$record
);
}
}
..
Impact
======
Extensions may now perform any kind of processing for every record when validating content links.
......@@ -224,6 +224,8 @@ class LinkAnalyzer {
* @return void
*/
public function analyzeRecord(array &$results, $table, array $fields, array $record) {
list($results, $record) = $this->emitBeforeAnalyzeRecordSignal($results, $record, $table, $fields);
// Put together content of all relevant fields
$haystack = '';
/** @var $htmlParser HtmlParser */
......@@ -463,6 +465,37 @@ class LinkAnalyzer {
return $hidden;
}
/**
* Emits a signal before the record is analyzed
*
* @param array $results Array of broken links
* @param array $record Record to analyse
* @param string $table Table name of the record
* @param array $fields Array of fields to analyze
* @return array
*/
protected function emitBeforeAnalyzeRecordSignal($results, $record, $table, $fields) {
return $this->getSignalSlotDispatcher()->dispatch(
self::class,
'beforeAnalyzeRecord',
array($results, $record, $table, $fields, $this)
);
}
/**
* @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected function getSignalSlotDispatcher() {
return $this->getObjectManager()->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
}
/**
* @return \TYPO3\CMS\Extbase\Object\ObjectManager
*/
protected function getObjectManager() {
return GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
}
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
*/
......
Supports Markdown
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