diff --git a/wcfsetup/install/files/acp/templates/contactRecipientAdd.tpl b/wcfsetup/install/files/acp/templates/contactRecipientAdd.tpl
index cd66c9ed55c..e183a042973 100644
--- a/wcfsetup/install/files/acp/templates/contactRecipientAdd.tpl
+++ b/wcfsetup/install/files/acp/templates/contactRecipientAdd.tpl
@@ -14,79 +14,6 @@
-{include file='shared_formNotice'}
-
-
+{unsafe:$form->getHtml()}
{include file='footer'}
diff --git a/wcfsetup/install/files/lib/acp/form/ContactRecipientAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ContactRecipientAddForm.class.php
index e2a59ed7261..bc64989f816 100644
--- a/wcfsetup/install/files/lib/acp/form/ContactRecipientAddForm.class.php
+++ b/wcfsetup/install/files/lib/acp/form/ContactRecipientAddForm.class.php
@@ -4,22 +4,23 @@
use wcf\data\contact\recipient\ContactRecipient;
use wcf\data\contact\recipient\ContactRecipientAction;
-use wcf\data\contact\recipient\ContactRecipientEditor;
-use wcf\form\AbstractForm;
-use wcf\system\email\Mailbox;
-use wcf\system\exception\UserInputException;
-use wcf\system\language\I18nHandler;
-use wcf\system\request\LinkHandler;
-use wcf\system\WCF;
+use wcf\data\contact\recipient\ContactRecipientList;
+use wcf\form\AbstractFormBuilderForm;
+use wcf\system\form\builder\field\BooleanFormField;
+use wcf\system\form\builder\field\EmailFormField;
+use wcf\system\form\builder\field\ShowOrderFormField;
+use wcf\system\form\builder\field\TextFormField;
/**
* Shows the form to create a new contact form recipient.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
+ * @author Olaf Braun, Alexander Ebert
+ * @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License
+ *
+ * @extends AbstractFormBuilderForm
*/
-class ContactRecipientAddForm extends AbstractForm
+class ContactRecipientAddForm extends AbstractFormBuilderForm
{
/**
* @inheritDoc
@@ -36,166 +37,56 @@ class ContactRecipientAddForm extends AbstractForm
*/
public $neededPermissions = ['admin.contact.canManageContactForm'];
- /**
- * email address
- * @var string
- */
- public $email = '';
-
- /**
- * display name
- * @var string
- */
- public $name = '';
-
- /**
- * 1 if the recipient is disabled
- * @var int
- */
- public $isDisabled = 0;
-
- /**
- * order used to the show the recipients
- * @var int
- */
- public $showOrder = 0;
-
/**
* @inheritDoc
*/
- public function readParameters()
- {
- parent::readParameters();
-
- I18nHandler::getInstance()->register('email');
- I18nHandler::getInstance()->register('name');
- }
+ public $objectActionClass = ContactRecipientAction::class;
/**
* @inheritDoc
*/
- public function readFormParameters()
- {
- parent::readFormParameters();
-
- I18nHandler::getInstance()->readValues();
-
- if (I18nHandler::getInstance()->isPlainValue('email')) {
- $this->email = I18nHandler::getInstance()->getValue('email');
- }
- if (I18nHandler::getInstance()->isPlainValue('name')) {
- $this->name = I18nHandler::getInstance()->getValue('name');
- }
-
- if (isset($_POST['isDisabled'])) {
- $this->isDisabled = \intval($_POST['isDisabled']);
- }
- if (isset($_POST['showOrder'])) {
- $this->showOrder = \intval($_POST['showOrder']);
- }
- }
+ public $objectEditLinkController = ContactRecipientEditForm::class;
- /**
- * @inheritDoc
- */
- public function validate()
- {
- parent::validate();
-
- if (!I18nHandler::getInstance()->validateValue('email')) {
- if (I18nHandler::getInstance()->isPlainValue('email')) {
- throw new UserInputException('email');
- } else {
- throw new UserInputException('email', 'multilingual');
- }
- } else {
- foreach (I18nHandler::getInstance()->getValues('email') as $email) {
- try {
- new Mailbox($email);
- } catch (\DomainException $e) {
- throw new UserInputException('email', 'invalid');
- }
- }
- }
-
- if (!I18nHandler::getInstance()->validateValue('name')) {
- if (I18nHandler::getInstance()->isPlainValue('name')) {
- throw new UserInputException('name');
- } else {
- throw new UserInputException('name', 'multilingual');
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- public function save()
+ #[\Override]
+ protected function createForm()
{
- parent::save();
-
- $this->objectAction = new ContactRecipientAction([], 'create', [
- 'data' => \array_merge($this->additionalFields, [
- 'name' => $this->name,
- 'email' => $this->email,
- 'isDisabled' => ($this->isDisabled ? 1 : 0),
- 'showOrder' => $this->showOrder,
- ]),
- ]);
- /** @var ContactRecipient $recipient */
- $recipient = $this->objectAction->executeAction()['returnValues'];
- $recipientID = $recipient->recipientID;
- $data = [];
+ parent::createForm();
- if (!I18nHandler::getInstance()->isPlainValue('email')) {
- I18nHandler::getInstance()->save('email', 'wcf.contact.recipient.email' . $recipientID, 'wcf.contact', 1);
+ $isAdministratorRecipient = $this->formAction === 'edit' && $this->formObject->isAdministrator;
- $data['email'] = 'wcf.contact.recipient.email' . $recipientID;
- }
- if (!I18nHandler::getInstance()->isPlainValue('name')) {
- I18nHandler::getInstance()->save('name', 'wcf.contact.recipient.name' . $recipientID, 'wcf.contact', 1);
-
- $data['name'] = 'wcf.contact.recipient.name' . $recipientID;
- }
+ $emailFormField = EmailFormField::create('email')
+ ->label('wcf.user.email')
+ ->immutable($isAdministratorRecipient)
+ ->required();
- // update i18n values
- if (!empty($data)) {
- (new ContactRecipientEditor($recipient))->update($data);
+ if (!$isAdministratorRecipient) {
+ $emailFormField->i18n()
+ ->languageItemPattern('wcf.contact.recipient.email\d+');
}
- $this->saved();
-
- // show success message
- WCF::getTPL()->assign([
- 'success' => true,
- 'objectEditLink' => LinkHandler::getInstance()->getControllerLink(
- ContactRecipientEditForm::class,
- ['id' => $recipientID]
- ),
+ $this->form->appendChildren([
+ TextFormField::create('name')
+ ->label('wcf.acp.contact.recipient.name')
+ ->i18n()
+ ->languageItemPattern('wcf.contact.recipient.name\d+')
+ ->required(),
+ $emailFormField,
+ ShowOrderFormField::create()
+ ->options($this->getContactRecipient()),
+ BooleanFormField::create('isDisabled')
+ ->label('wcf.acp.contact.recipient.isDisabled'),
]);
-
- // reset values
- $this->email = $this->name = '';
- $this->isDisabled = $this->showOrder = 0;
-
- I18nHandler::getInstance()->reset();
}
/**
- * @inheritDoc
+ * @return array
*/
- public function assignVariables()
+ private function getContactRecipient(): array
{
- parent::assignVariables();
-
- I18nHandler::getInstance()->assignVariables();
+ $recipientList = new ContactRecipientList();
+ $recipientList->sqlOrderBy = 'showOrder ASC';
+ $recipientList->readObjects();
- WCF::getTPL()->assign([
- 'action' => 'add',
- 'email' => $this->email,
- 'name' => $this->name,
- 'isDisabled' => $this->isDisabled,
- 'showOrder' => $this->showOrder,
- ]);
+ return \array_map(static fn ($recipient) => $recipient->getName(), $recipientList->getObjects());
}
}
diff --git a/wcfsetup/install/files/lib/acp/form/ContactRecipientEditForm.class.php b/wcfsetup/install/files/lib/acp/form/ContactRecipientEditForm.class.php
index 1f629a191bc..ae7617c2904 100644
--- a/wcfsetup/install/files/lib/acp/form/ContactRecipientEditForm.class.php
+++ b/wcfsetup/install/files/lib/acp/form/ContactRecipientEditForm.class.php
@@ -3,17 +3,13 @@
namespace wcf\acp\form;
use wcf\data\contact\recipient\ContactRecipient;
-use wcf\data\contact\recipient\ContactRecipientAction;
-use wcf\form\AbstractForm;
use wcf\system\exception\IllegalLinkException;
-use wcf\system\language\I18nHandler;
-use wcf\system\WCF;
/**
* Shows the form to update a contact form recipient.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
+ * @author Olaf Braun, Alexander Ebert
+ * @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License
*/
class ContactRecipientEditForm extends ContactRecipientAddForm
@@ -34,14 +30,9 @@ class ContactRecipientEditForm extends ContactRecipientAddForm
public $neededPermissions = ['admin.contact.canManageContactForm'];
/**
- * @var ContactRecipient
- */
- public $recipient;
-
- /**
- * @var int
+ * @inheritDoc
*/
- public $recipientID = 0;
+ public $formAction = 'edit';
/**
* @inheritDoc
@@ -50,103 +41,13 @@ public function readParameters()
{
parent::readParameters();
- if (isset($_REQUEST['id'])) {
- $this->recipientID = \intval($_REQUEST['id']);
- }
- $this->recipient = new ContactRecipient($this->recipientID);
- if (!$this->recipient->recipientID) {
+ if (!isset($_REQUEST['id'])) {
throw new IllegalLinkException();
}
- }
-
- /**
- * @inheritDoc
- */
- public function readData()
- {
- parent::readData();
-
- if (empty($_POST)) {
- I18nHandler::getInstance()->setOptions(
- 'name',
- 1,
- $this->recipient->name,
- 'wcf.contact.recipient.name\d+'
- );
- I18nHandler::getInstance()->setOptions(
- 'email',
- 1,
- $this->recipient->email,
- 'wcf.contact.recipient.email\d+'
- );
-
- $this->name = $this->recipient->name;
- $this->email = $this->recipient->email;
- $this->isDisabled = $this->recipient->isDisabled;
- $this->showOrder = $this->recipient->showOrder;
-
- if ($this->recipient->isAdministrator) {
- $this->email = MAIL_ADMIN_ADDRESS;
- }
- }
- }
- /**
- * @inheritDoc
- */
- public function save()
- {
- AbstractForm::save();
-
- $this->name = 'wcf.contact.recipient.name' . $this->recipient->recipientID;
- if (I18nHandler::getInstance()->isPlainValue('name')) {
- I18nHandler::getInstance()->remove($this->name);
- $this->name = I18nHandler::getInstance()->getValue('name');
- } else {
- I18nHandler::getInstance()->save('name', $this->name, 'wcf.contact', 1);
- }
- $this->email = 'wcf.contact.recipient.email' . $this->recipient->recipientID;
- if (!$this->recipient->isAdministrator) {
- if (I18nHandler::getInstance()->isPlainValue('email')) {
- I18nHandler::getInstance()->remove($this->email);
- $this->email = I18nHandler::getInstance()->getValue('email');
- } else {
- I18nHandler::getInstance()->save('email', $this->email, 'wcf.contact', 1);
- }
- }
-
- $data = [
- 'name' => $this->name,
- 'isDisabled' => $this->isDisabled ? 1 : 0,
- 'showOrder' => $this->showOrder,
- ];
- if (!$this->recipient->isAdministrator) {
- $data['email'] = $this->email;
+ $this->formObject = new ContactRecipient(\intval($_REQUEST['id']));
+ if (!$this->formObject->recipientID) {
+ throw new IllegalLinkException();
}
-
- $this->objectAction = new ContactRecipientAction([$this->recipient], 'update', [
- 'data' => \array_merge($this->additionalFields, $data),
- ]);
- $this->objectAction->executeAction();
- $this->saved();
-
- // show success message
- WCF::getTPL()->assign('success', true);
- }
-
- /**
- * @inheritDoc
- */
- public function assignVariables()
- {
- parent::assignVariables();
-
- I18nHandler::getInstance()->assignVariables(!empty($_POST));
-
- WCF::getTPL()->assign([
- 'recipientID' => $this->recipientID,
- 'recipient' => $this->recipient,
- 'action' => 'edit',
- ]);
}
}
diff --git a/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php b/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php
index 9e6d7220c47..a45412230b0 100644
--- a/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php
+++ b/wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php
@@ -3,26 +3,25 @@
namespace wcf\data\contact\recipient;
use wcf\data\AbstractDatabaseObjectAction;
-use wcf\data\ISortableAction;
use wcf\data\IToggleAction;
use wcf\data\TDatabaseObjectToggle;
+use wcf\data\TI18nDatabaseObjectAction;
use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\UserInputException;
-use wcf\system\WCF;
/**
* Executes contact recipient related actions.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
+ * @author Olaf Braun, Alexander Ebert
+ * @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License
* @since 3.1
*
* @extends AbstractDatabaseObjectAction
*/
-class ContactRecipientAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction
+class ContactRecipientAction extends AbstractDatabaseObjectAction implements IToggleAction
{
use TDatabaseObjectToggle;
+ use TI18nDatabaseObjectAction;
/**
* @inheritDoc
@@ -71,44 +70,62 @@ public function validateToggle()
parent::validateUpdate();
}
- /**
- * @inheritDoc
- */
- public function validateUpdatePosition()
+ #[\Override]
+ public function create()
{
- WCF::getSession()->checkPermissions($this->permissionsUpdate);
-
- if (!isset($this->parameters['data']['structure']) || !\is_array($this->parameters['data']['structure'])) {
- throw new UserInputException('structure');
+ // Database columns do not have default values
+ if (!isset($this->parameters['data']['name'])) {
+ $this->parameters['data']['name'] = '';
}
-
- $recipientList = new ContactRecipientList();
- $recipientList->setObjectIDs($this->parameters['data']['structure'][0]);
- if ($recipientList->countObjects() != \count($this->parameters['data']['structure'][0])) {
- throw new UserInputException('structure');
+ if (!isset($this->parameters['data']['email'])) {
+ $this->parameters['data']['email'] = '';
}
- $this->readInteger('offset', true, 'data');
+ $contactRecipient = parent::create();
+
+ $this->saveI18nValue($contactRecipient);
+
+ return $contactRecipient;
}
- /**
- * @inheritDoc
- */
- public function updatePosition()
+ #[\Override]
+ public function delete()
{
- $sql = "UPDATE wcf1_contact_recipient
- SET showOrder = ?
- WHERE recipientID = ?";
- $statement = WCF::getDB()->prepare($sql);
-
- $showOrder = $this->parameters['data']['offset'];
- WCF::getDB()->beginTransaction();
- foreach ($this->parameters['data']['structure'][0] as $recipientID) {
- $statement->execute([
- $showOrder++,
- $recipientID,
- ]);
+ $count = parent::delete();
+
+ $this->deleteI18nValues();
+
+ return $count;
+ }
+
+ #[\Override]
+ public function update()
+ {
+ parent::update();
+
+ foreach ($this->getObjects() as $contactRecipient) {
+ $this->saveI18nValue($contactRecipient->getDecoratedObject());
}
- WCF::getDB()->commitTransaction();
+ }
+
+ #[\Override]
+ public function getI18nSaveTypes(): array
+ {
+ return [
+ 'name' => 'wcf.contact.recipient.name\d+',
+ 'email' => 'wcf.contact.recipient.email\d+',
+ ];
+ }
+
+ #[\Override]
+ public function getLanguageCategory(): string
+ {
+ return 'wcf.contact';
+ }
+
+ #[\Override]
+ public function getPackageID(): int
+ {
+ return 1;
}
}