Fixes the problem that the `externalURL` was not saved
authorCyperghost <olaf_schmitz_1@t-online.de>
Thu, 21 Nov 2024 08:24:07 +0000 (09:24 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Thu, 21 Nov 2024 08:24:07 +0000 (09:24 +0100)
wcfsetup/install/files/lib/acp/form/MenuItemAddForm.class.php
wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php

index 2824e7fae4fbe7188d7a020057d350fa2d559575..934dd61162c90097f7bc67149994587bde792d35 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\acp\form;
 
+use wcf\data\IStorableObject;
 use wcf\data\menu\item\MenuItem;
 use wcf\data\menu\item\MenuItemAction;
 use wcf\data\menu\item\MenuItemNodeTree;
@@ -223,11 +224,17 @@ class MenuItemAddForm extends AbstractFormBuilderForm
                             $parameters['data']['externalURL'] = '';
                         } else {
                             $parameters['data']['pageID'] = null;
-                            $parameters['data']['pageObjectID'] = null;
+                            $parameters['data']['pageObjectID'] = 0;
                         }
                         unset($parameters['data']['isInternalLink']);
 
                         return $parameters;
+                    },
+                    function (IFormDocument $document, array $data, IStorableObject $object) {
+                        \assert($object instanceof MenuItem);
+                        $data['isInternalLink'] = $object->pageID !== null;
+
+                        return $data;
                     }
                 )
             );
index f14767603b483be4839eacf168453ecc1a466980..a8c71595c82de22943edf6343c336f21d564de7a 100644 (file)
@@ -171,7 +171,10 @@ class MenuItemAction extends AbstractDatabaseObjectAction implements ISortableAc
     #[\Override]
     public function getI18nSaveTypes(): array
     {
-        return ['title' => 'wcf.menu.item.\w+'];
+        return [
+            'title' => 'wcf.menu.item.\w+',
+            'externalURL' => 'wcf.menu.item.externalURL\d+',
+        ];
     }
 
     #[\Override]
@@ -189,11 +192,14 @@ class MenuItemAction extends AbstractDatabaseObjectAction implements ISortableAc
     protected function getLanguageItem(DatabaseObject $object, string $regex): string
     {
         \assert($object instanceof MenuItem);
-
-        return \str_replace(
-            '\w+',
-            $object->identifier ?: 'com.woltlab.wcf.generic' . $object->itemID,
-            $regex
-        );
+        if (\str_contains($regex, '\d+')) {
+            return \str_replace('\d+', $object->itemID, $regex);
+        } else {
+            return \str_replace(
+                '\w+',
+                $object->identifier ?: 'com.woltlab.wcf.generic' . $object->itemID,
+                $regex
+            );
+        }
     }
 }