Add `AbstractTemplateDeletePackageInstallationPlugin`
authorMatthias Schmidt <gravatronics@live.com>
Tue, 8 Jun 2021 11:47:22 +0000 (13:47 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 8 Jun 2021 15:12:55 +0000 (17:12 +0200)
wcfsetup/install/files/lib/system/package/plugin/AbstractTemplateDeletePackageInstallationPlugin.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractTemplateDeletePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractTemplateDeletePackageInstallationPlugin.class.php
new file mode 100644 (file)
index 0000000..8618171
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace wcf\system\package\plugin;
+
+use wcf\system\form\builder\field\TextFormField;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\form\builder\field\validation\FormFieldValidator;
+use wcf\system\form\builder\IFormDocument;
+
+/**
+ * Abstract implementation of a package installation plugin deleting a certain type of templates.
+ *
+ * @author  Matthias Schmidt
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Package\Plugin
+ * @since   5.5
+ */
+abstract class AbstractTemplateDeletePackageInstallationPlugin extends AbstractFileDeletePackageInstallationPlugin
+{
+    /**
+     * @inheritDoc
+     */
+    public $tagName = 'template';
+
+    /**
+     * @inheritDoc
+     */
+    protected function getFilenameTableColumn(): string
+    {
+        return 'templateName';
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected function addFormFields(IFormDocument $form)
+    {
+        parent::addFormFields($form);
+
+        /** @var TextFormField $templateFormField */
+        $templateFormField = $form->getNodeById($this->tagName);
+        $templateFormField->addValidator(new FormFieldValidator('tplSuffix', static function (TextFormField $formField) {
+            if (\substr($formField->getValue(), -4) === '.tpl') {
+                $formField->addValidationError(new FormFieldValidationError(
+                    'tplSuffix',
+                    'wcf.acp.pip.acpTemplateDelete.template.error.tplSuffix'
+                ));
+            }
+        }));
+    }
+}