Fix I18n values for reaction types
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 6 Aug 2018 10:24:23 +0000 (12:24 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 6 Aug 2018 10:24:23 +0000 (12:24 +0200)
See #2508

wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php

index 4be7cece214572393df6f4fa1ce2af9c83fde01c..02a5a73d642f35b1b4e16b0ed25808e7d814bd99 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\ISortableAction;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
+use wcf\system\language\I18nHandler;
 use wcf\system\WCF;
 
 /**
@@ -34,6 +35,57 @@ class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortab
         */
        protected $requireACP = ['delete', 'update', 'updatePosition'];
        
+       /**
+        * @inheritDoc
+        */
+       public function create() {
+               /** @var ReactionType $reactionType */
+               $reactionType = parent::create();
+               $reactionTypeEditor = new ReactionTypeEditor($reactionType);
+               
+               // i18n
+               $updateData = [];
+               if (isset($this->parameters['title_i18n'])) {
+                       I18nHandler::getInstance()->save(
+                               $this->parameters['title_i18n'],
+                               'wcf.reactionType.title' . $reactionType->reactionTypeID,
+                               'wcf.reactionType',
+                               1
+                       );
+                       
+                       $updateData['title'] = 'wcf.reactionType.title' . $reactionType->reactionTypeID;
+               }
+               
+               if (!empty($updateData)) {
+                       $reactionTypeEditor->update($updateData);
+               }
+               
+               return $reactionType;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function update() {
+               parent::update();
+               
+               // i18n
+               foreach ($this->getObjects() as $object) {
+                       if (isset($this->parameters['title_i18n'])) {
+                               I18nHandler::getInstance()->save(
+                                       $this->parameters['title_i18n'],
+                                       'wcf.reactionType.title' . $object->reactionTypeID,
+                                       'wcf.reactionType',
+                                       1
+                               );
+                               
+                               $object->update([
+                                       'title' => 'wcf.reactionType.title' . $object->reactionTypeID
+                               ]);
+                       }
+               }
+       }
+       
        /**
         * @inheritDoc
         */