Makes description optional for category types
authorMatthias Schmidt <gravatronics@live.com>
Sat, 14 Jul 2012 15:36:28 +0000 (17:36 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 14 Jul 2012 15:36:28 +0000 (17:36 +0200)
wcfsetup/install/files/acp/templates/categoryAdd.tpl
wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php
wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php
wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php
wcfsetup/install/files/lib/system/category/ICategoryType.class.php

index 3c6d35943a5a3d8b2efc1733ed6d4719228f3adf..1c6a10425989b93f7bbb81e8c50d6fc6b8152cf2 100644 (file)
@@ -9,18 +9,15 @@
                {if $aclObjectTypeID}
                        new WCF.ACL.List($('#groupPermissions'), {@$aclObjectTypeID}{if $category|isset}, '', {@$category->categoryID}{/if});
                {/if}
-               
-               var $availableLanguages = { {implode from=$availableLanguages key=languageID item=languageName}{@$languageID}: '{$languageName}'{/implode} };
-               
-               var $titleValues = { {implode from=$i18nValues['title'] key=languageID item=value}'{@$languageID}': '{$value}'{/implode} };
-               new WCF.MultipleLanguageInput('title', false, $titleValues, $availableLanguages);
-               
-               var $descriptionValues = { {implode from=$i18nValues['description'] key=languageID item=value}'{@$languageID}': '{$value}'{/implode} };
-               new WCF.MultipleLanguageInput('description', false, $descriptionValues, $availableLanguages);
        });
        //]]>
 </script>
 
+{include file='multipleLanguageInputJavascript' elementIdentifier='title'}
+{if $objectType->getProcessor()->supportsDescriptions()}
+       {include file='multipleLanguageInputJavascript' elementIdentifier='description'}
+{/if}
+
 <header class="boxHeadline">
        <hgroup>
                <h1>{@$objectType->getProcessor()->getLanguageVariable($action)}</h1>
                                </dd>
                        </dl>
                        
-                       <dl{if $errorField == 'description'} class="formError"{/if}>
-                               <dt><label for="description">{@$objectType->getProcessor()->getLanguageVariable('description')}</label></dt>
-                               <dd>
-                                       <textarea cols="40" rows="10" id="description" name="description">{$i18nPlainValues['description']}</textarea>
-                                       {if $errorField == 'description'}
-                                               <small class="innerError">
-                                                       {if $errorType == 'empty'}
-                                                               {lang}wcf.global.form.error.empty{/lang}
-                                                       {else}
-                                                               {assign var=__languageVariable value='description.error.'|concat:$errorType}
-                                                               {@$objectType->getProcessor()->getLanguageVariable($__languageVariable)}
-                                                       {/if}
-                                               </small>
-                                       {/if}
-                                       {hascontent}<small>{content}{@$objectType->getProcessor()->getLanguageVariable('description.description', true)}{/content}</small>{/hascontent}
-                               </dd>
-                       </dl>
+                       {if $objectType->getProcessor()->supportsDescriptions()}
+                               <dl{if $errorField == 'description'} class="formError"{/if}>
+                                       <dt><label for="description">{@$objectType->getProcessor()->getLanguageVariable('description')}</label></dt>
+                                       <dd>
+                                               <textarea cols="40" rows="10" id="description" name="description">{$i18nPlainValues['description']}</textarea>
+                                               {if $errorField == 'description'}
+                                                       <small class="innerError">
+                                                               {if $errorType == 'empty'}
+                                                                       {lang}wcf.global.form.error.empty{/lang}
+                                                               {else}
+                                                                       {assign var=__languageVariable value='description.error.'|concat:$errorType}
+                                                                       {@$objectType->getProcessor()->getLanguageVariable($__languageVariable)}
+                                                               {/if}
+                                                       </small>
+                                               {/if}
+                                               {hascontent}<small>{content}{@$objectType->getProcessor()->getLanguageVariable('description.description', true)}{/content}</small>{/hascontent}
+                                       </dd>
+                               </dl>
+                       {/if}
                        
                        <dl{if $errorField == 'isDisabled'} class="formError"{/if}>
                                <dt class="reversed"><label for="isDisabled">{@$objectType->getProcessor()->getLanguageVariable('isDisabled')}</label></dt>
                                </dd>
                        </dl>
                        
-                       {if $aclObjectTypeID}
-                               <dl id="groupPermissions">
+                       {event name='dataFields'}
+               </fieldset>
+               
+               {if $aclObjectTypeID}
+                       <fieldset>
+                               <legend>{lang}wcf.acp.acl.permissions{/lang}</legend>
+
+                               <dl id="groupPermissions" class="wide">
                                        <dt>{lang}wcf.acp.acl.permissions{/lang}</dt>
                                        <dd></dd>
                                </dl>
-                       {/if}
-                       
-                       {event name='fields'}
-               </fieldset>
+                               
+                               {event name='permissionFields'}
+                       </fieldset>
+               {/if}
                
                {event name='fieldsets'}
        </div>
index 3fb3c6ddb50efa06be577e9fb46eef836d745fff..a30ad81ef2ccde88f4e4424005c0b98d47ca8861 100644 (file)
@@ -196,6 +196,11 @@ abstract class AbstractCategoryAddForm extends ACPForm {
                        $this->packageID = $this->objectType->packageID;
                }
                
+               if ($this->objectType->getProcessor()->supportsDescriptions()) {
+                       I18nHandler::getInstance()->register('description');
+               }
+               I18nHandler::getInstance()->register('title');
+               
                parent::readData();
                
                $this->readCategories();
@@ -212,7 +217,7 @@ abstract class AbstractCategoryAddForm extends ACPForm {
                if (isset($_POST['additionalData'])) {
                        $this->additionalData = ArrayUtil::trim($_POST['additionalData']);
                }
-               if (isset($_POST['description'])) {
+               if ($this->objectType->getProcessor()->supportsDescriptions() && isset($_POST['description'])) {
                        $this->description = StringUtil::trim($_POST['description']);
                }
                if (isset($_POST['isDisabled'])) {
@@ -229,16 +234,6 @@ abstract class AbstractCategoryAddForm extends ACPForm {
                }
        }
        
-       /**
-        * @see wcf\page\IPage::readParameters()
-        */
-       public function readParameters() {
-               parent::readParameters();
-               
-               I18nHandler::getInstance()->register('description');
-               I18nHandler::getInstance()->register('title');
-       }
-       
        /**
         * @see wcf\page\IForm::save()
         */
@@ -259,11 +254,11 @@ abstract class AbstractCategoryAddForm extends ACPForm {
                $this->objectAction->executeAction();
                $returnValues = $this->objectAction->getReturnValues();
                
-               if (!I18nHandler::getInstance()->isPlainValue('description') || !I18nHandler::getInstance()->isPlainValue('title')) {
+               if (($this->objectType->getProcessor()->supportsDescriptions() && !I18nHandler::getInstance()->isPlainValue('description')) || !I18nHandler::getInstance()->isPlainValue('title')) {
                        $categoryID = $returnValues['returnValues']->categoryID;
                        
                        $updateData = array();
-                       if (!I18nHandler::getInstance()->isPlainValue('description')) {
+                       if ($this->objectType->getProcessor()->supportsDescriptions() && !I18nHandler::getInstance()->isPlainValue('description')) {
                                $updateData['description'] = $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category'.$categoryID;
                                I18nHandler::getInstance()->save('description', $updateData['description'], $this->objectType->getProcessor()->getDescriptionLangVarCategory(), $this->packageID);
                        }
@@ -310,7 +305,7 @@ abstract class AbstractCategoryAddForm extends ACPForm {
                        throw new UserInputException('title');
                }
                
-               if (!I18nHandler::getInstance()->validateValue('description')) {
+               if ($this->objectType->getProcessor()->supportsDescriptions() && !I18nHandler::getInstance()->validateValue('description')) {
                        throw new UserInputException('description');
                }
        }
index 740114b182342918aae4c06f1b70616eb048fe35..9f89e4e0998740cf2c18940084910cd8d02e9b7d 100644 (file)
@@ -86,7 +86,9 @@ class AbstractCategoryEditForm extends AbstractCategoryAddForm {
                parent::readData();
                
                if (empty($_POST)) {
-                       I18nHandler::getInstance()->setOptions('description', $this->packageID, $this->category->description, $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category\d+');
+                       if ($this->objectType->getProcessor()->supportsDescriptions()) {
+                               I18nHandler::getInstance()->setOptions('description', $this->packageID, $this->category->description, $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category\d+');
+                       }
                        I18nHandler::getInstance()->setOptions('title', $this->packageID, $this->category->title, $this->objectType->getProcessor()->getI18nLangVarPrefix().'.title.category\d+');
                        
                        $this->additionalData = $this->category->additionalData;
@@ -103,13 +105,15 @@ class AbstractCategoryEditForm extends AbstractCategoryAddForm {
                ACPForm::save();
                
                // handle description
-               $this->description = $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category'.$this->category->categoryID;
-               if (I18nHandler::getInstance()->isPlainValue('description')) {
-                       I18nHandler::getInstance()->remove($this->description, $this->packageID);
-                       $this->description = I18nHandler::getInstance()->getValue('description');
-               }
-               else {
-                       I18nHandler::getInstance()->save('description', $this->description, $this->objectType->getProcessor()->getDescriptionLangVarCategory(), $this->packageID);
+               if ($this->objectType->getProcessor()->supportsDescriptions()) {
+                       $this->description = $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category'.$this->category->categoryID;
+                       if (I18nHandler::getInstance()->isPlainValue('description')) {
+                               I18nHandler::getInstance()->remove($this->description, $this->packageID);
+                               $this->description = I18nHandler::getInstance()->getValue('description');
+                       }
+                       else {
+                               I18nHandler::getInstance()->save('description', $this->description, $this->objectType->getProcessor()->getDescriptionLangVarCategory(), $this->packageID);
+                       }
                }
                
                // handle title
index ad42a23c2447d4fbdbea261eae02b83cf9a4b1dc..7c3ba1effb704edb783dff5702fb2fbf98942b72 100644 (file)
@@ -45,6 +45,12 @@ abstract class AbstractCategoryType extends SingletonFactory implements ICategor
         */
        protected $permissionPrefix = '';
        
+       /**
+        * indicates if the category type supports descriptions
+        * @var boolean
+        */
+       protected $supportsDescriptions = true;
+       
        /**
         * @see wcf\system\category\ICategoryType::afterDeletion()
         */
@@ -127,4 +133,11 @@ abstract class AbstractCategoryType extends SingletonFactory implements ICategor
        public function getTitleLangVarCategory() {
                return $this->i18nLangVarCategory;
        }
+       
+       /**
+        * @see wcf\system\category\ICategoryType::supportsDescriptions()
+        */
+       public function supportsDescriptions() {
+               return $this->supportsDescriptions;
+       }
 }
index 49a5349b860a1603bab6168274ec5cf362a1fa7e..5c3436e045c3b5a20d57d39c028bdcb3e03309a0 100644 (file)
@@ -94,4 +94,11 @@ interface ICategoryType {
         * @return      string
         */
        public function getTitleLangVarCategory();
+       
+       /**
+        * Returns true if categories of this type support descriptions.
+        * 
+        * @return      boolean
+        */
+       public function supportsDescriptions();
 }