Skip to content

EspoCRM – Open Source CRM Application

Language field backend validations

Yurii8bcb9991b537
diff --git a/application/Espo/Classes/FieldValidators/Preferences/Language/Valid.php b/application/Espo/Classes/FieldValidators/Preferences/Language/Valid.php
new file mode 100644
index 0000000000..20c32251c1
--- /dev/null
+++ b/application/Espo/Classes/FieldValidators/Preferences/Language/Valid.php
@@ -0,0 +1,65 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Classes\FieldValidators\Preferences\Language;
+
+use Espo\Core\FieldValidation\Validator;
+use Espo\Core\FieldValidation\Validator\Data;
+use Espo\Core\FieldValidation\Validator\Failure;
+use Espo\Core\Utils\Metadata;
+use Espo\Entities\Preferences;
+use Espo\ORM\Entity;
+
+/**
+ * @implements Validator<Preferences>
+ */
+class Valid implements Validator
+{
+ public function __construct(
+ private Metadata $metadata,
+ ) {}
+
+ public function validate(Entity $entity, string $field, Data $data): ?Failure
+ {
+ $value = $entity->getLanguage();
+
+ if ($value === null) {
+ return null;
+ }
+
+ /** @var string[] $list */
+ $list = $this->metadata->get("app.language.list", []);
+
+ if (in_array($value, $list)) {
+ return null;
+ }
+
+ return Failure::create();
+ }
+}
diff --git a/application/Espo/Classes/FieldValidators/Settings/Language/Valid.php b/application/Espo/Classes/FieldValidators/Settings/Language/Valid.php
new file mode 100644
index 0000000000..beb0bd9b6b
--- /dev/null
+++ b/application/Espo/Classes/FieldValidators/Settings/Language/Valid.php
@@ -0,0 +1,61 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Classes\FieldValidators\Settings\Language;
+
+use Espo\Core\FieldValidation\Validator;
+use Espo\Core\FieldValidation\Validator\Data;
+use Espo\Core\FieldValidation\Validator\Failure;
+use Espo\Core\Utils\Metadata;
+use Espo\Entities\Settings;
+use Espo\ORM\Entity;
+
+/**
+ * @implements Validator<Settings>
+ */
+class Valid implements Validator
+{
+ public function __construct(
+ private Metadata $metadata,
+ ) {}
+
+ public function validate(Entity $entity, string $field, Data $data): ?Failure
+ {
+ $value = $entity->get($field);
+
+ /** @var string[] $list */
+ $list = $this->metadata->get("app.language.list", []);
+
+ if (in_array($value, $list)) {
+ return null;
+ }
+
+ return Failure::create();
+ }
+}
diff --git a/application/Espo/Resources/metadata/entityDefs/Preferences.json b/application/Espo/Resources/metadata/entityDefs/Preferences.json
index e0b6633b52..38d07eb4b2 100644
--- a/application/Espo/Resources/metadata/entityDefs/Preferences.json
+++ b/application/Espo/Resources/metadata/entityDefs/Preferences.json
@@ -70,7 +70,10 @@
},
"language": {
"type": "enum",
- "view": "views/preferences/fields/language"
+ "view": "views/preferences/fields/language",
+ "validatorClassNameList": [
+ "Espo\\Classes\\FieldValidators\\Preferences\\Language\\Valid"
+ ]
},
"exportDelimiter": {
"type": "varchar",
diff --git a/application/Espo/Resources/metadata/entityDefs/Settings.json b/application/Espo/Resources/metadata/entityDefs/Settings.json
index 84ac3a4522..f2a761dc00 100644
--- a/application/Espo/Resources/metadata/entityDefs/Settings.json
+++ b/application/Espo/Resources/metadata/entityDefs/Settings.json
@@ -262,7 +262,10 @@
"type": "enum",
"default": "en_US",
"view": "views/settings/fields/language",
- "isSorted": true
+ "isSorted": true,
+ "validatorClassNameList": [
+ "Espo\\Classes\\FieldValidators\\Settings\\Language\\Valid"
+ ]
},
"globalSearchEntityList": {
"type": "multiEnum",