--- /dev/null
+{include file='__formFieldHeader'}
+
+<noscript>
+ <select name="{@$field->getPrefixedId()}" id="{@$field->getPrefixedId()}"{if $field->isImmutable()} disabled{/if}>
+ {if !$field->isRequired()}
+ <option>{lang}wcf.global.language.noSelection{/lang}</option>
+ {/if}
+ {foreach from=$field->getContentLanguages() item=contentLanguage}
+ <option value="{@$contentLanguage->languageID}">{$contentLanguage}</option>
+ {/foreach}
+ </select>
+</noscript>
+
+<script data-relocate="true">
+ require(['WoltLabSuite/Core/Language/Chooser', 'Dom/Traverse', 'Dom/Util'], function(LanguageChooser, DomTraverse, DomUtil) {
+ var languages = {
+ {implode from=$field->getContentLanguages() item=contentLanguage}
+ '{@$contentLanguage->languageID}': {
+ iconPath: '{@$contentLanguage->getIconPath()|encodeJS}',
+ languageName: '{@$contentLanguage|encodeJS}'
+ }
+ {/implode}
+ };
+
+ LanguageChooser.init(
+ DomUtil.identify(DomTraverse.childByTag(elById('{@$field->getPrefixedId()}Container'), 'DD')),
+ '{@$field->getPrefixedId()}',
+ {if $field->getValue()}{@$field->getValue()}{else}0{/if},
+ languages,
+ undefined,
+ {if !$field->isRequired()}true{else}false{/if}
+ )
+ });
+</script>
+
+{include file='__formFieldFooter'}
"templates": [
"__aclFormField",
"__booleanFormField",
+ "__contentLanguageFormField",
"__dateFormField",
"__devtoolsLanguageChooser",
"__form",
--- /dev/null
+{include file='__formFieldHeader'}
+
+<noscript>
+ <select name="{@$field->getPrefixedId()}" id="{@$field->getPrefixedId()}"{if $field->isImmutable()} disabled{/if}>
+ {if !$field->isRequired()}
+ <option>{lang}wcf.global.language.noSelection{/lang}</option>
+ {/if}
+ {foreach from=$field->getContentLanguages() item=contentLanguage}
+ <option value="{@$contentLanguage->languageID}">{$contentLanguage}</option>
+ {/foreach}
+ </select>
+</noscript>
+
+<script data-relocate="true">
+ require(['WoltLabSuite/Core/Language/Chooser', 'Dom/Traverse', 'Dom/Util'], function(LanguageChooser, DomTraverse, DomUtil) {
+ var languages = {
+ {implode from=$field->getContentLanguages() item=contentLanguage}
+ '{@$contentLanguage->languageID}': {
+ iconPath: '{@$contentLanguage->getIconPath()|encodeJS}',
+ languageName: '{@$contentLanguage|encodeJS}'
+ }
+ {/implode}
+ };
+
+ LanguageChooser.init(
+ DomUtil.identify(DomTraverse.childByTag(elById('{@$field->getPrefixedId()}Container'), 'DD')),
+ '{@$field->getPrefixedId()}',
+ {if $field->getValue()}{@$field->getValue()}{else}0{/if},
+ languages,
+ undefined,
+ {if !$field->isRequired()}true{else}false{/if}
+ )
+ });
+</script>
+
+{include file='__formFieldFooter'}
'wcf.global.form.error.lessThan': '{lang __literal=true}wcf.global.form.error.lessThan{/lang}',
'wcf.global.form.error.multilingual': '{lang}wcf.global.form.error.multilingual{/lang}',
'wcf.global.form.input.maxItems': '{lang}wcf.global.form.input.maxItems{/lang}',
+ 'wcf.global.language.noSelection': '{lang}wcf.global.language.noSelection{/lang}',
'wcf.global.loading': '{lang}wcf.global.loading{/lang}',
'wcf.global.noSelection': '{lang}wcf.global.noSelection{/lang}',
'wcf.global.select': '{lang}wcf.global.select{/lang}',
--- /dev/null
+/**
+ * Data handler for a content language form builder field in an Ajax form.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Language/ContentLanguage
+ * @since 5.2
+ */
+define(['Core', 'WoltLabSuite/Core/Language/Chooser', '../Value'], function(Core, LanguageChooser, FormBuilderFieldValue) {
+ "use strict";
+
+ /**
+ * @constructor
+ */
+ function FormBuilderFieldContentLanguage(fieldId) {
+ this.init(fieldId);
+ };
+ Core.inherit(FormBuilderFieldContentLanguage, FormBuilderFieldValue, {
+ /**
+ * @see WoltLabSuite/Core/Form/Builder/Field/Field#destroy
+ */
+ destroy: function() {
+ LanguageChooser.removeChooser(this._fieldId);
+ }
+ });
+
+ return FormBuilderFieldContentLanguage;
+});
if (element.parentNode.nodeName === 'DD') {
container = elCreate('div');
container.className = 'dropdown';
- element.parentNode.insertBefore(container, element);
+
+ // language chooser is the first child so that descriptions and error messages
+ // are always shown below the language chooser
+ DomUtil.prepend(container, element.parentNode);
}
else {
container = element.parentNode;
--- /dev/null
+<?php
+namespace wcf\system\form\builder\field\language;
+use wcf\system\form\builder\field\AbstractFormField;
+use wcf\system\form\builder\field\IImmutableFormField;
+use wcf\system\form\builder\field\TDefaultIdFormField;
+use wcf\system\form\builder\field\TImmutableFormField;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\language\LanguageFactory;
+
+/**
+ * Implementation of a form field for to select the language of a certain content.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Form\Builder\Field\Language
+ * @since 5.2
+ */
+class ContentLanguageFormField extends AbstractFormField implements IImmutableFormField {
+ use TDefaultIdFormField;
+ use TImmutableFormField;
+
+ /**
+ * @inheritDoc
+ */
+ protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Language/ContentLanguage';
+
+ /**
+ * @inheritDoc
+ */
+ protected $templateName = '__contentLanguageFormField';
+
+ /**
+ * Creates a new instance of `ContentLanguageFormField`.
+ */
+ public function __construct() {
+ $this->label('wcf.user.language');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getContentLanguages() {
+ return LanguageFactory::getInstance()->getContentLanguages();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function isAvailable() {
+ return LanguageFactory::getInstance()->multilingualismEnabled()
+ && !empty(LanguageFactory::getInstance()->getContentLanguageIDs())
+ && parent::isAvailable();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function readValue() {
+ if ($this->getDocument()->hasRequestData($this->getPrefixedId())) {
+ $this->value = intval($this->getDocument()->getRequestData($this->getPrefixedId()));
+
+ if (!$this->isRequired() && !$this->value) {
+ $this->value = null;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function validate() {
+ if ($this->isRequired() && LanguageFactory::getInstance()->getLanguage($this->getValue()) === null) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'invalidValue',
+ 'wcf.global.form.error.noValidSelection'
+ ));
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ protected static function getDefaultId() {
+ return 'languageID';
+ }
+}