Standardize poll input names
authorjoshuaruesweg <ruesweg@woltlab.com>
Tue, 1 Feb 2022 10:41:00 +0000 (11:41 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Tue, 1 Feb 2022 12:35:11 +0000 (13:35 +0100)
The old implementation uses names like `pollQuestion` instead of `Poll_question`. Unifying these, make it easier to maintain the code and use the TypeScript implementation for old and new code.

ts/WoltLabSuite/Core/Ui/Poll/Editor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Poll/Editor.js
wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygPollFormContainer.class.php

index 4b064e8eee556679295af04e5264f99e603276d2..5a458e6177c17b41ee63f571f011a1f2d5de4614 100644 (file)
@@ -313,7 +313,7 @@ class UiPollEditor {
       this.getOptions().forEach((option, i) => {
         const input = document.createElement("input");
         input.type = "hidden";
-        input.name = `${this.wysiwygId}Poll_options[${i}]`;
+        input.name = `${this.wysiwygId}pollOptions[${i}]`;
         input.value = option;
         form.appendChild(input);
       });
@@ -361,6 +361,7 @@ class UiPollEditor {
     return {
       [this.questionField.id]: this.questionField.value,
       [this.wysiwygId + "Poll_options"]: this.getOptions(),
+      [this.wysiwygId + "pollOptions"]: this.getOptions(),
       [this.endTimeField.id]: this.endTimeField.value,
       [this.maxVotesField.id]: this.maxVotesField.value,
       [this.isChangeableYesField.id]: !!this.isChangeableYesField.checked,
index 1a34f53eb88d1e285ed3c3561904494303edebc0..87efe5f7897edd7fcc5c85fd6a1ff04081f3f4f6 100644 (file)
@@ -222,7 +222,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta
                 this.getOptions().forEach((option, i) => {
                     const input = document.createElement("input");
                     input.type = "hidden";
-                    input.name = `${this.wysiwygId}Poll_options[${i}]`;
+                    input.name = `${this.wysiwygId}pollOptions[${i}]`;
                     input.value = option;
                     form.appendChild(input);
                 });
@@ -267,6 +267,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Language", "../Sorta
             return {
                 [this.questionField.id]: this.questionField.value,
                 [this.wysiwygId + "Poll_options"]: this.getOptions(),
+                [this.wysiwygId + "pollOptions"]: this.getOptions(),
                 [this.endTimeField.id]: this.endTimeField.value,
                 [this.maxVotesField.id]: this.maxVotesField.value,
                 [this.isChangeableYesField.id]: !!this.isChangeableYesField.checked,
index 4efddde9e6b51c0170cec0564b640cfefe0e54de..76abb0b3482dff211eeb07761b8cceac1260f804 100644 (file)
@@ -286,7 +286,7 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
     {
         parent::populate();
 
-        $id = $this->wysiwygId . 'Poll';
+        $id = $this->wysiwygId . 'poll';
 
         // add data handler to group poll data into a sub-array of parameters
         $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor(
@@ -299,8 +299,8 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
                 $wysiwygId = $this->getWysiwygId();
 
                 foreach (self::FIELD_NAMES as $fieldName) {
-                    $parameters[$wysiwygId . '_pollData'][$fieldName] = $parameters['data'][$id . '_' . $fieldName];
-                    unset($parameters['data'][$id . '_' . $fieldName]);
+                    $parameters[$wysiwygId . '_pollData'][$fieldName] = $parameters['data'][$id . \ucfirst($fieldName)];
+                    unset($parameters['data'][$id . \ucfirst($fieldName)]);
                 }
 
                 // this will always add a poll array to the parameters but
@@ -311,16 +311,16 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
             }
         ));
 
-        $this->questionField = TextFormField::create($id . '_question')
+        $this->questionField = TextFormField::create($id . 'Question')
             ->label('wcf.poll.question')
             ->maximumLength(255);
 
         // if either options or question is given, the other must also be given
-        $this->optionsField = PollOptionsFormField::create($id . '_options')
+        $this->optionsField = PollOptionsFormField::create($id . 'Options')
             ->wysiwygId($this->getWysiwygId())
             ->addValidator(new FormFieldValidator('empty', static function (PollOptionsFormField $formField) use ($id) {
                 /** @var TextFormField $questionFormField */
-                $questionFormField = $formField->getDocument()->getNodeById($id . '_question');
+                $questionFormField = $formField->getDocument()->getNodeById($id . 'Question');
 
                 if (empty($formField->getValue()) && $questionFormField->getValue() !== '') {
                     $formField->addValidationError(new FormFieldValidationError('empty'));
@@ -329,7 +329,7 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
                 }
             }));
 
-        $this->endTimeField = DateFormField::create($id . '_endTime')
+        $this->endTimeField = DateFormField::create($id . 'EndTime')
             ->label('wcf.poll.endTime')
             ->supportTime()
             ->addValidator(new FormFieldValidator('futureTime', function (DateFormField $formField) {
@@ -345,13 +345,13 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
                 }
             }));
 
-        $this->maxVotesField = IntegerFormField::create($id . '_maxVotes')
+        $this->maxVotesField = IntegerFormField::create($id . 'MaxVotes')
             ->label('wcf.poll.maxVotes')
             ->minimum(1)
             ->maximum(POLL_MAX_OPTIONS)
             ->value(1);
 
-        $this->isChangeableField = BooleanFormField::create($id . '_isChangeable')
+        $this->isChangeableField = BooleanFormField::create($id . 'IsChangeable')
             ->label('wcf.poll.isChangeable');
 
         /** @var IPollHandler $pollHandler */
@@ -360,15 +360,15 @@ class WysiwygPollFormContainer extends FormContainer implements IObjectTypeFormN
             $pollHandler = $this->getObjectType()->getProcessor();
         }
 
-        $this->isPublicField = BooleanFormField::create($id . '_isPublic')
+        $this->isPublicField = BooleanFormField::create($id . 'IsPublic')
             ->label('wcf.poll.isPublic')
             ->available($pollHandler !== null && $pollHandler->canStartPublicPoll());
 
-        $this->resultsRequireVoteField = BooleanFormField::create($id . '_resultsRequireVote')
+        $this->resultsRequireVoteField = BooleanFormField::create($id . 'ResultsRequireVote')
             ->label('wcf.poll.resultsRequireVote')
             ->description('wcf.poll.resultsRequireVote.description');
 
-        $this->sortByVotesField = BooleanFormField::create($id . '_sortByVotes')
+        $this->sortByVotesField = BooleanFormField::create($id . 'SortByVotes')
             ->label('wcf.poll.sortByVotes');
 
         $this->appendChildren([