[FEATURE] Add hook for used/unused content record processing 11/53811/15
authorClaus Due <claus@namelesscoder.net>
Sat, 26 Aug 2017 19:28:43 +0000 (21:28 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 15 Nov 2017 11:05:44 +0000 (12:05 +0100)
This patch adds a new hook to determine whether a content record is
used or not. Since the default decision is fairly basic (only checks if
$columns contains $record['colPos']) a hook makes it possible for third
party extensions to change the decision and validate on their own.

Included rst file shows how to register to the hook and provides example
code how to determine the result.

Resolves: #82213
Releases: master
Change-Id: Id338254dae6575ba7b91141c10a42b99401614c9
Reviewed-on: https://review.typo3.org/53811
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Claus Due <claus@phpmind.net>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Tested-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com>
Tested-by: Benjamin Kott <benjamin.kott@outlook.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/core/Documentation/Changelog/master/Feature-82213-NewHookToDetermineIfContentRecordIsUsedUnused.rst [new file with mode: 0644]

index 271269e..056c03e 100644 (file)
@@ -1615,8 +1615,14 @@ class PageLayoutView implements LoggerAwareInterface
         // Traverse any selected elements and render their display code:
         $results = $this->getResult($queryBuilder->execute());
         $unused = [];
+        $hookArray = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used'] ?? [];
         foreach ($results as $record) {
-            if (isset($columns[$record['colPos']])) {
+            $used = isset($columns[$record['colPos']]);
+            foreach ($hookArray as $_funcRef) {
+                $_params = ['columns' => $columns, 'record' => $record, 'used' => $used];
+                $used = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
+            }
+            if ($used) {
                 $columnValue = (string)$record['colPos'];
                 $contentRecordsPerColumn[$columnValue][] = $record;
             } else {
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-82213-NewHookToDetermineIfContentRecordIsUsedUnused.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-82213-NewHookToDetermineIfContentRecordIsUsedUnused.rst
new file mode 100644 (file)
index 0000000..e95ac27
--- /dev/null
@@ -0,0 +1,48 @@
+.. include:: ../../Includes.txt
+
+========================================================================
+Feature: #82213 - New hook to determine if content record is used/unused
+========================================================================
+
+See :issue:`82213`
+
+Description
+===========
+
+A new hook has been added to the `PageLayoutView` class, determining whether a
+content record is used or not. The hook allows third party code to change the
+`$used` parameter by returning a boolean, thus changing which content records
+are shown in the "unused content elements" section of the backend page module.
+
+
+Impact
+======
+
+Without providing an own hook, content elements with an colPos not defined within
+the current backend layout are marked as unused. You have to register and provide
+an own PHP class checking if an content record is used within your configuration.
+
+.. code-block:: php
+
+    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used']['myExt'] =
+    MyExt\MyExt\Hooks\PageLayoutViewHook::class . '->contentIsUsed';
+
+.. code-block:: php
+
+    namespace MyExt\MyExt\Hooks;
+
+    use TYPO3\CMS\Backend\View\PageLayoutView;
+
+    class PageLayoutViewHook
+    {
+        public function contentIsUsed(array $params, PageLayoutView $parentObject): bool
+        {
+            if ($params['used']) {
+               return true;
+            }
+            $record = $params['record'];
+            return $record['colPos'] === 999 && !empty($record['tx_myext_content_parent']);
+        }
+    }
+
+.. index:: Backend