public function validate() {
parent::validate();
+ if (!$this->isMultilingual && !$this->languageID) {
+ throw new UserInputException('languageID');
+ }
+
if ($this->languageID && !LanguageFactory::getInstance()->getLanguage($this->languageID)) {
throw new UserInputException('languageID');
}
foreach (['title', 'caption', 'altText'] as $i18nData) {
- if (!I18nHandler::getInstance()->validateValue($i18nData, $this->isMultilingual? true : false, false)) {
+ if (!I18nHandler::getInstance()->validateValue($i18nData, $this->isMultilingual? true : false, true)) {
if ($this->isMultilingual) {
// in contrast to I18nHandler::validateValues(), we allow all fields to be empty
if (empty(ArrayUtil::trim(I18nHandler::getInstance()->getValues($i18nData)))) {
}
}
- // TODO: check data
+ $this->readInteger('languageID', true, 'data');
+ $this->readBoolean('isMultilingual', true, 'data');
+
+ // languageID: convert zero to null
+ if (!$this->parameters['data']['languageID']) $this->parameters['data']['languageID'] = null;
+
+ // isMultilingual: convert boolean to integer
+ $this->parameters['data']['isMultilingual'] = intval($this->parameters['data']['isMultilingual']);
+
+ // if data is not multilingual, a language id has to be given
+ if (!$this->parameters['data']['isMultilingual'] && !$this->parameters['data']['languageID']) {
+ throw new UserInputException('languageID');
+ }
+
+ // check language id
+ if ($this->parameters['data']['languageID'] && !LanguageFactory::getInstance()->getLanguage($this->parameters['data']['languageID'])) {
+ throw new UserInputException('languageID');
+ }
}
/**