[FEATURE] Add signal for pre proccesing records 76/24276/18
authorBenjamin Serfhos <serfhos@gmail.com>
Wed, 2 Oct 2013 15:21:11 +0000 (17:21 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 6 Aug 2015 12:43:17 +0000 (14:43 +0200)
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: Jesper Paardekooper <jesper.paardekooper@gmail.com>
Tested-by: Jesper Paardekooper <jesper.paardekooper@gmail.com>
Reviewed-by: Frank N├Ągler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Feature-52217-SignalForPreProccesingLinkvalidatorRecords.rst [new file with mode: 0644]
typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-52217-SignalForPreProccesingLinkvalidatorRecords.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-52217-SignalForPreProccesingLinkvalidatorRecords.rst
new file mode 100644 (file)
index 0000000..75e9dab
--- /dev/null
@@ -0,0 +1,59 @@
+=================================================================
+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.
index b460a14..ea21ac6 100644 (file)
@@ -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 */
@@ -464,6 +466,37 @@ class LinkAnalyzer {
        }
 
        /**
+        * 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
         */
        protected function getDatabaseConnection() {