From 26fc1611812824a186e4eb38429fa376270af596 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Wed, 15 Dec 2021 17:16:54 +0100
Subject: [PATCH] [TASK] Simplify ext:belog "max" drop down code

The "max" drop down in the ext:belog filter html
is the only one that uses belog:form.translateLabelSelect
view helper.
By refactoring slightly, we can drop this view
helper and simplify the code a bit.

Resolves: #96360
Related: main
Change-Id: Ib952dd3475d952354f8a07c31917f88751b93704
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72664
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../Controller/BackendLogController.php       | 16 ++++
 .../Form/TranslateLabelSelectViewHelper.php   | 74 -------------------
 .../Configuration/TypoScript/setup.typoscript | 22 ------
 .../Resources/Private/Language/locallang.xlf  | 15 ----
 .../Private/Partials/Content/Filter.html      |  5 +-
 .../belog/ext_typoscript_setup.typoscript     |  1 -
 6 files changed, 18 insertions(+), 115 deletions(-)
 delete mode 100644 typo3/sysext/belog/Classes/ViewHelpers/Form/TranslateLabelSelectViewHelper.php
 delete mode 100644 typo3/sysext/belog/Configuration/TypoScript/setup.typoscript
 delete mode 100644 typo3/sysext/belog/ext_typoscript_setup.typoscript

diff --git a/typo3/sysext/belog/Classes/Controller/BackendLogController.php b/typo3/sysext/belog/Classes/Controller/BackendLogController.php
index d0d63f2c2061..214dc1d3c06e 100644
--- a/typo3/sysext/belog/Classes/Controller/BackendLogController.php
+++ b/typo3/sysext/belog/Classes/Controller/BackendLogController.php
@@ -101,6 +101,7 @@ class BackendLogController extends ActionController
             'groupedLogEntries' => $groupedLogEntries,
             'constraint' => $constraint,
             'userGroups' => $this->createUserAndGroupListForSelectOptions(),
+            'selectableNumberOfLogEntries' => $this->createSelectableNumberOfLogEntriesOptions(),
             'workspaces' => $this->createWorkspaceListForSelectOptions(),
             'pageDepths' => $this->createPageDepthOptions(),
             'channels' => $this->logEntryRepository->getUsedChannels(),
@@ -240,6 +241,21 @@ class BackendLogController extends ActionController
         return $userGroupArray;
     }
 
+    /**
+     * Options for the "max" drop down
+     */
+    protected function createSelectableNumberOfLogEntriesOptions(): array
+    {
+        return [
+            50 => 50,
+            100 => 100,
+            200 => 200,
+            500 => 500,
+            1000 => 1000,
+            1000000 => LocalizationUtility::translate('any', 'Belog'),
+        ];
+    }
+
     /**
      * Create options for the workspace selector
      *
diff --git a/typo3/sysext/belog/Classes/ViewHelpers/Form/TranslateLabelSelectViewHelper.php b/typo3/sysext/belog/Classes/ViewHelpers/Form/TranslateLabelSelectViewHelper.php
deleted file mode 100644
index b3d345b218ff..000000000000
--- a/typo3/sysext/belog/Classes/ViewHelpers/Form/TranslateLabelSelectViewHelper.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-namespace TYPO3\CMS\Belog\ViewHelpers\Form;
-
-use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
-use TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper;
-
-/**
- * Extends the usual select ViewHelper, but additionally translates
- * the select option labels
- *
- * Example:
- * <belog:form.translateLabelSelect property="number" options="{settings.selectableNumberOfLogEntries}" optionLabelPrefix="numbers"
- *
- * Will lookup number.200 (or whatever optionValue is given) in locallang database
- * @internal
- */
-class TranslateLabelSelectViewHelper extends SelectViewHelper
-{
-    /**
-     * Initialize arguments.
-     */
-    public function initializeArguments()
-    {
-        parent::initializeArguments();
-        $this->registerArgument('optionLabelPrefix', 'string', 'Prefix for locallang lookup');
-    }
-
-    /**
-     * Render the option tags.
-     *
-     * Extend the default handling by iterating over calculated options array and
-     * try to translate the value
-     *
-     * @return array An associative array of options, key will be the value of the option tag
-     */
-    protected function getOptions()
-    {
-        $options = parent::getOptions();
-        foreach ($options as $value => $label) {
-            $options[$value] = $this->translateLabel($label);
-        }
-        return $options;
-    }
-
-    /**
-     * Fetches the translation for a given label. If no translation is found, the label is returned unchanged.
-     *
-     * @param string $label The label to translate
-     * @return string
-     */
-    protected function translateLabel($label)
-    {
-        if ($label === '') {
-            return '';
-        }
-        $labelKey = $this->hasArgument('optionLabelPrefix') ? $this->arguments['optionLabelPrefix'] . $label : $label;
-        $translatedLabel = LocalizationUtility::translate($labelKey, $this->renderingContext->getRequest()->getControllerExtensionName());
-        return $translatedLabel ?: $label;
-    }
-}
diff --git a/typo3/sysext/belog/Configuration/TypoScript/setup.typoscript b/typo3/sysext/belog/Configuration/TypoScript/setup.typoscript
deleted file mode 100644
index 448b4b0f10d2..000000000000
--- a/typo3/sysext/belog/Configuration/TypoScript/setup.typoscript
+++ /dev/null
@@ -1,22 +0,0 @@
-module.tx_belog {
-	settings {
-		selectableNumberOfLogEntries {
-			50 = 50
-			100 = 100
-			200 = 200
-			500 = 500
-			1000 = 1000
-			1000000 = any
-		}
-
-		selectableActions {
-			0 = any
-			1 = actionDatabase
-			2 = actionFile
-			3 = actionCache
-			254 = actionSettings
-			255 = actionLogin
-			-1 = actionErrors
-		}
-	}
-}
diff --git a/typo3/sysext/belog/Resources/Private/Language/locallang.xlf b/typo3/sysext/belog/Resources/Private/Language/locallang.xlf
index 6244a832a879..3caff9f116f0 100644
--- a/typo3/sysext/belog/Resources/Private/Language/locallang.xlf
+++ b/typo3/sysext/belog/Resources/Private/Language/locallang.xlf
@@ -36,21 +36,6 @@
 			<trans-unit id="all" resname="all">
 				<source>[all]</source>
 			</trans-unit>
-			<trans-unit id="50" resname="50" translate="no">
-				<source>50</source>
-			</trans-unit>
-			<trans-unit id="100" resname="100" translate="no">
-				<source>100</source>
-			</trans-unit>
-			<trans-unit id="200" resname="200" translate="no">
-				<source>200</source>
-			</trans-unit>
-			<trans-unit id="500" resname="500" translate="no">
-				<source>500</source>
-			</trans-unit>
-			<trans-unit id="1000" resname="1000" translate="no">
-				<source>1000</source>
-			</trans-unit>
 			<trans-unit id="actionAll" resname="actionAll">
 				<source>All</source>
 			</trans-unit>
diff --git a/typo3/sysext/belog/Resources/Private/Partials/Content/Filter.html b/typo3/sysext/belog/Resources/Private/Partials/Content/Filter.html
index 646f14c957b5..7e483208f9a2 100644
--- a/typo3/sysext/belog/Resources/Private/Partials/Content/Filter.html
+++ b/typo3/sysext/belog/Resources/Private/Partials/Content/Filter.html
@@ -30,10 +30,9 @@
 
         <div class="col">
             <label for="belog-max" class="form-label"><f:translate key="max" /></label>
-            <belog:form.translateLabelSelect
+            <f:form.select
                 property="number"
-                options="{settings.selectableNumberOfLogEntries}"
-                optionLabelPrefix="LLL:EXT:belog/Resources/Private/Language/locallang.xlf:"
+                options="{selectableNumberOfLogEntries}"
                 class="form-select"
                 id="belog-max"
             />
diff --git a/typo3/sysext/belog/ext_typoscript_setup.typoscript b/typo3/sysext/belog/ext_typoscript_setup.typoscript
deleted file mode 100644
index 3b0a45d2eab7..000000000000
--- a/typo3/sysext/belog/ext_typoscript_setup.typoscript
+++ /dev/null
@@ -1 +0,0 @@
-<INCLUDE_TYPOSCRIPT: source="FILE:EXT:belog/Configuration/TypoScript/setup.typoscript">
-- 
GitLab