Default languages (de/en) can no longer be deleted
authorMarcel Werk <burntime@woltlab.com>
Thu, 25 Feb 2021 13:02:04 +0000 (14:02 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 25 Feb 2021 13:02:04 +0000 (14:02 +0100)
Closes #3969

wcfsetup/install/files/acp/templates/languageList.tpl
wcfsetup/install/files/lib/data/language/Language.class.php
wcfsetup/install/files/lib/data/language/LanguageAction.class.php

index 82edbb9963b28c74f0318738f8c569e25509d382..9df2e9a21809ff11e87fb31b72b2cb4684bc8b33 100644 (file)
@@ -68,7 +68,7 @@
                                                        
                                                        <a href="{link controller='LanguageEdit' id=$language->languageID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon16 fa-pencil"></span></a>
                                                        
-                                                       {if !$language->isDefault}
+                                                       {if $language->isDeletable()}
                                                                <span class="icon icon16 fa-times jsTooltip jsDeleteButton pointer" title="{lang}wcf.global.button.delete{/lang}" data-object-id="{@$language->languageID}" data-confirm-message-html="{lang __encode=true}wcf.acp.language.delete.sure{/lang}"></span>
                                                        {else}
                                                                <span class="icon icon16 fa-times disabled" title="{lang}wcf.global.button.delete{/lang}"></span>
index 2020ee92d8be0138c5533a0bf39e02fe229637d1..e0a5a16c2a0d8fee358fdd0a0ec77afd9d832412 100644 (file)
@@ -295,4 +295,14 @@ class Language extends DatabaseObject
     {
         $this->packageID = PACKAGE_ID;
     }
+
+    /**
+     * Returns true if this language can be deleted.
+     *
+     * @since   5.4
+     */
+    public function isDeletable(): bool
+    {
+        return !$this->isDefault && $this->languageCode !== 'de' && $this->languageCode !== 'en';
+    }
 }
index 9673f9bd406833608da24e9831c02477d831775d..b589b2fce69d5bb6d4068ed7c2c1b50c22264d23 100644 (file)
@@ -90,4 +90,18 @@ class LanguageAction extends AbstractDatabaseObjectAction implements IToggleActi
             }
         }
     }
+
+    /**
+     * @inheritDoc
+     */
+    public function validateDelete()
+    {
+        parent::validateDelete();
+
+        foreach ($this->getObjects() as $language) {
+            if (!$language->isDeletable()) {
+                throw new UserInputException('objectIDs');
+            }
+        }
+    }
 }