sluggi icon indicating copy to clipboard operation
sluggi copied to clipboard

Call to undefined function ...\array_flatten() when saving page

Open Nobiteer opened this issue 7 months ago • 8 comments

After updating from 12.1.2 to 12.1.3 we get an error 503 every time we try to save a page. Error message: Call to undefined funtion Wazum\Sluggi\DataHandler\array_flatten()

Versions

TYPO3: 12.4.31 PHP: 8.1.32

Image

Quick fix: Go back to 12.1.2

Nobiteer avatar May 27 '25 12:05 Nobiteer

Thanks for the report @Nobiteer, obviously it worked in one of my simple tests two days ago, but I moved the declaration of array_flatten into ext_localconf.php, so the method should now be available everywhere. Please re-install the same tag 12.1.3 (due to the short time span between release and your report I allowed myself to use the same) and give me feedback, if the problem is resolved (I couldn't find any error messages in the backend). https://github.com/wazum/sluggi/commit/7b89c8e08e0eb7be4380f9c502d10a052a0817c4

wazum avatar May 28 '25 12:05 wazum

… i had the same issues here, thx for the immediate fix. isn't the use of TYPO3 API »ArrayUtility« possible?

https://api.typo3.org/12.4/classes/TYPO3-CMS-Core-Utility-ArrayUtility.html#method_flatten methods: flatten() or flattenPlain()

zarthwork avatar May 28 '25 13:05 zarthwork

First of all: Thanks for the quick fix!

I would agree with @zarthwork's suggestion, if that is possible. For the versioning: I am not a composer geek but wouldn't that mean, that users who already got 12.1.3 wouldn't get the fix at their next update, but only when Sluggi reaches 12.1.4?

Nobiteer avatar May 28 '25 16:05 Nobiteer

Thanks for the quickfix. Unfortunately the function is still not found when you open some Install-Tool-Wizards like "Check TCA Migrations" and "Check TCA in ext_tables.php".

Call to undefined function array_flatten() in /vendor/wazum/sluggi/Configuration/TCA/Overrides/pages.php line 63

GFZcoder avatar Jul 01 '25 13:07 GFZcoder

... Please re-install the same tag 12.1.3 (due to the short time span between release and your report I allowed myself to use the same) and give me feedback, if the problem is resolved ... This is a bad practice as composer uses caches to avoid fetching the same packages again and again. Please consider releasing a new version instead.

woemar avatar Jul 18 '25 06:07 woemar

Thanks guys, I'll take another look at the issue (with more time) and release a new version.

wazum avatar Jul 18 '25 08:07 wazum

Sorry, I am a bit in a hurry but this might be a solution for version 12.1.3: Move array_flatten to a helper class

diff --git a/Classes/DataHandler/HandlePageUpdate.php b/Classes/DataHandler/HandlePageUpdate.php
index fa9d8ea..2b08de3 100644
--- a/Classes/DataHandler/HandlePageUpdate.php
+++ b/Classes/DataHandler/HandlePageUpdate.php
@@ -17,6 +17,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Redirects\RedirectUpdate\SlugRedirectChangeItemFactory;
+use Wazum\Sluggi\Helper\ArrayHelper;
 use Wazum\Sluggi\Helper\Configuration;
 use Wazum\Sluggi\Helper\PermissionHelper;
 use Wazum\Sluggi\Helper\SlugHelper as SluggiSlugHelper;
@@ -366,7 +367,7 @@ final class HandlePageUpdate implements LoggerAwareInterface
			 return false;
		 }
 
-        $slugFields = array_flatten($relevantFields);
+        $slugFields = ArrayHelper::array_flatten($relevantFields);
		 foreach ($slugFields as $field) {
			 if (isset($fields[$field]) && $fields[$field] !== ($pageRecord[$field] ?? null)) {
				 return true;
diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php
index 0b3301e..5477fd2 100644
--- a/Configuration/TCA/Overrides/pages.php
+++ b/Configuration/TCA/Overrides/pages.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
 
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use Wazum\Sluggi\Backend\SlugModifier;
+use Wazum\Sluggi\Helper\ArrayHelper;
 use Wazum\Sluggi\Helper\Configuration;
 
 defined('TYPO3') || exit;
@@ -60,7 +61,7 @@ defined('TYPO3') || exit;
			 $GLOBALS['TCA']['pages']['columns']['slug']['config']['generatorOptions']['fields'] = $pagesFieldsForSlug;
		 }
 
-        foreach (array_flatten($pagesFieldsForSlug ?? []) as $field) {
+        foreach (ArrayHelper::array_flatten($pagesFieldsForSlug ?? []) as $field) {
			 if (isset($GLOBALS['TCA']['pages']['columns'][$field]['config'])) {
				 $GLOBALS['TCA']['pages']['columns'][$field]['config']['renderType'] = 'inputTextWithSlugImpact';
			 }
diff --git a/ext_localconf.php b/ext_localconf.php
index 249ace2..9959aa2 100644
--- a/ext_localconf.php
+++ b/ext_localconf.php
@@ -18,27 +18,6 @@ use Wazum\Sluggi\Service\SlugService;
 
 defined('TYPO3') || exit;
 
-if (!function_exists('array_flatten')) {
-    /**
-     * @param array<array-key, mixed> $array
-     *
-     * @return array<array-key, mixed>
-     */
-    function array_flatten(array $array): array
-    {
-        $merged = [[]];
-        foreach ($array as $value) {
-            if (is_array($value)) {
-                $merged[] = array_flatten($value);
-            } else {
-                $merged[] = [$value];
-            }
-        }
-
-        return array_merge([], ...$merged);
-    }
-}
-
 (static function (): void {
	 // Register some DataHandler hooks for page related actions
	 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['sluggi-update']

woemar avatar Jul 18 '25 08:07 woemar

Confirming the problem in TYPO3 v12 with the TCA migration tool from Install Tool.

Somehow the patch from @woemar didn't apply locally, I used this one instead:

diff --git a/Classes/DataHandler/HandlePageUpdate.php b/Classes/DataHandler/HandlePageUpdate.php
index fa9d8ea..2b08de3 100644
--- a/Classes/DataHandler/HandlePageUpdate.php
+++ b/Classes/DataHandler/HandlePageUpdate.php
@@ -17,6 +17,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Redirects\RedirectUpdate\SlugRedirectChangeItemFactory;
+use Wazum\Sluggi\Helper\ArrayHelper;
 use Wazum\Sluggi\Helper\Configuration;
 use Wazum\Sluggi\Helper\PermissionHelper;
 use Wazum\Sluggi\Helper\SlugHelper as SluggiSlugHelper;
@@ -366,7 +367,7 @@ final class HandlePageUpdate implements LoggerAwareInterface
             return false;
         }
 
-        $slugFields = array_flatten($relevantFields);
+        $slugFields = ArrayHelper::array_flatten($relevantFields);
         foreach ($slugFields as $field) {
             if (isset($fields[$field]) && $fields[$field] !== ($pageRecord[$field] ?? null)) {
                 return true;
diff --git a/Classes/Helper/ArrayHelper.php b/Classes/Helper/ArrayHelper.php
new file mode 100644
index 0000000..faf7ec0
--- /dev/null
+++ b/Classes/Helper/ArrayHelper.php
@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Wazum\Sluggi\Helper;
+
+final class ArrayHelper
+{
+    public static function array_flatten(array $array): array
+    {
+        $merged = [[]];
+        foreach ($array as $value) {
+            if (is_array($value)) {
+                $merged[] = static::array_flatten($value);
+            } else {
+                $merged[] = [$value];
+            }
+        }
+
+        return array_merge([], ...$merged);
+    }
+}
diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php
index 0b3301e..5477fd2 100644
--- a/Configuration/TCA/Overrides/pages.php
+++ b/Configuration/TCA/Overrides/pages.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
 
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use Wazum\Sluggi\Backend\SlugModifier;
+use Wazum\Sluggi\Helper\ArrayHelper;
 use Wazum\Sluggi\Helper\Configuration;
 
 defined('TYPO3') || exit;
@@ -60,7 +61,7 @@ defined('TYPO3') || exit;
             $GLOBALS['TCA']['pages']['columns']['slug']['config']['generatorOptions']['fields'] = $pagesFieldsForSlug;
         }
 
-        foreach (array_flatten($pagesFieldsForSlug ?? []) as $field) {
+        foreach (ArrayHelper::array_flatten($pagesFieldsForSlug ?? []) as $field) {
             if (isset($GLOBALS['TCA']['pages']['columns'][$field]['config'])) {
                 $GLOBALS['TCA']['pages']['columns'][$field]['config']['renderType'] = 'inputTextWithSlugImpact';
             }
diff --git a/ext_localconf.php b/ext_localconf.php
index 249ace2..9959aa2 100644
--- a/ext_localconf.php
+++ b/ext_localconf.php
@@ -18,27 +18,6 @@ use Wazum\Sluggi\Service\SlugService;
 
 defined('TYPO3') || exit;
 
-if (!function_exists('array_flatten')) {
-    /**
-     * @param array<array-key, mixed> $array
-     *
-     * @return array<array-key, mixed>
-     */
-    function array_flatten(array $array): array
-    {
-        $merged = [[]];
-        foreach ($array as $value) {
-            if (is_array($value)) {
-                $merged[] = array_flatten($value);
-            } else {
-                $merged[] = [$value];
-            }
-        }
-
-        return array_merge([], ...$merged);
-    }
-}
-
 (static function (): void {
     // Register some DataHandler hooks for page related actions
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['sluggi-update']

xperseguers avatar Sep 11 '25 09:09 xperseguers