From a833c68b9e2ae747d5ffdffd3bce1ea606c4e88d Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 14 Jul 2012 17:36:28 +0200 Subject: [PATCH] Makes description optional for category types --- .../files/acp/templates/categoryAdd.tpl | 67 ++++++++++--------- .../form/AbstractCategoryAddForm.class.php | 23 +++---- .../form/AbstractCategoryEditForm.class.php | 20 +++--- .../category/AbstractCategoryType.class.php | 13 ++++ .../system/category/ICategoryType.class.php | 7 ++ 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/categoryAdd.tpl b/wcfsetup/install/files/acp/templates/categoryAdd.tpl index 3c6d35943a..1c6a104259 100644 --- a/wcfsetup/install/files/acp/templates/categoryAdd.tpl +++ b/wcfsetup/install/files/acp/templates/categoryAdd.tpl @@ -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); }); //]]> +{include file='multipleLanguageInputJavascript' elementIdentifier='title'} +{if $objectType->getProcessor()->supportsDescriptions()} + {include file='multipleLanguageInputJavascript' elementIdentifier='description'} +{/if} +

{@$objectType->getProcessor()->getLanguageVariable($action)}

@@ -93,23 +90,25 @@ - -
-
- - {if $errorField == 'description'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {assign var=__languageVariable value='description.error.'|concat:$errorType} - {@$objectType->getProcessor()->getLanguageVariable($__languageVariable)} - {/if} - - {/if} - {hascontent}{content}{@$objectType->getProcessor()->getLanguageVariable('description.description', true)}{/content}{/hascontent} -
- + {if $objectType->getProcessor()->supportsDescriptions()} + +
+
+ + {if $errorField == 'description'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {assign var=__languageVariable value='description.error.'|concat:$errorType} + {@$objectType->getProcessor()->getLanguageVariable($__languageVariable)} + {/if} + + {/if} + {hascontent}{content}{@$objectType->getProcessor()->getLanguageVariable('description.description', true)}{/content}{/hascontent} +
+ + {/if}
@@ -133,15 +132,21 @@ - {if $aclObjectTypeID} -
+ {event name='dataFields'} + + + {if $aclObjectTypeID} +
+ {lang}wcf.acp.acl.permissions{/lang} + +
{lang}wcf.acp.acl.permissions{/lang}
- {/if} - - {event name='fields'} -
+ + {event name='permissionFields'} + + {/if} {event name='fieldsets'} diff --git a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php index 3fb3c6ddb5..a30ad81ef2 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php @@ -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'); } } diff --git a/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php index 740114b182..9f89e4e099 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php index ad42a23c24..7c3ba1effb 100644 --- a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php @@ -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; + } } diff --git a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php index 49a5349b86..5c3436e045 100644 --- a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php @@ -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(); } -- 2.20.1