Skip to content

Commit

Permalink
Merge pull request #472 from matthiashamacher/feature/not-all-languag…
Browse files Browse the repository at this point in the history
…es-required

Add possibility to make languages not mandatory
  • Loading branch information
mcop1 authored Apr 26, 2024
2 parents 5b9c889 + 2d8d90e commit c783da2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
12 changes: 12 additions & 0 deletions public/js/pimcore/object/helpers/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ pimcore.object.helpers.edit = {
// add asterisk to mandatory field
l.titleOriginal = l.title;
let icons = '';
let wasMandatory = false;

if (context.containerType == 'localizedfield') {
if (l.mandatory && !in_array(context.language, pimcore.settings.requiredLanguages)) {
l.mandatory = false;
wasMandatory = true;
}
}

if(l.mandatory) {
icons += '<span style="color:red;">*</span>';
Expand Down Expand Up @@ -458,6 +466,10 @@ pimcore.object.helpers.edit = {
}
}

if (wasMandatory) {
l.mandatory = true;
}

return dLayout;
}
}
Expand Down
42 changes: 41 additions & 1 deletion public/js/pimcore/settings/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ pimcore.settings.system = Class.create({
id: "system_settings_general_validLanguages",
name: 'general.validLanguages',
value: this.getValue("general.valid_languages", true)
}, {
xtype: "hidden",
id: "system_settings_general_requiredLanguages",
name: 'general.requiredLanguages',
value: this.getValue("general.required_languages", true)
}, {
xtype: "hidden",
id: "system_settings_general_defaultLanguage",
Expand Down Expand Up @@ -596,11 +601,38 @@ pimcore.settings.system = Class.create({
}
}.bind(this)
}
}, {
xtype: "checkbox",
name: "general.requiredLanguage",
boxLabel: t("required_language"),
checked: this.getValue("general.required_languages", true).includes(language),
listeners: {
change: function (el, checked) {
var requiredLanguagesField = Ext.getCmp("system_settings_general_requiredLanguages");
var requiredLanguages = [];

if (requiredLanguagesField.getValue() != '') {
requiredLanguages = requiredLanguagesField.getValue().split(",");
}

if (checked) {
if (!in_array(language, requiredLanguages)) {
requiredLanguages.push(language);
}
} else {
if (in_array(language, requiredLanguages)) {
requiredLanguages.splice(array_search(language, requiredLanguages), 1);
}
}

requiredLanguagesField.setValue(requiredLanguages.join(","));
}.bind(this)
}
}, {
xtype: "button",
title: t("delete"),
iconCls: "pimcore_icon_delete",
style: "position:absolute; right: 5px; top:12px;",
style: "position:absolute; right: 5px; top:40px;",
handler: this.removeLanguage.bind(this, language)
}]
});
Expand All @@ -618,6 +650,14 @@ pimcore.settings.system = Class.create({
languageField.setValue(addedLanguages.join(","));
}

// remove the required language out of the hidden field
var requiredLanguagesField = Ext.getCmp("system_settings_general_requiredLanguages");
var addedRequiredLanguages = requiredLanguagesField.getValue().split(",");
if (in_array(language, addedRequiredLanguages)) {
addedRequiredLanguages.splice(array_search(language, addedRequiredLanguages), 1);
requiredLanguagesField.setValue(addedRequiredLanguages.join(","));
}

// remove the default language from hidden field
var defaultLanguageField = Ext.getCmp("system_settings_general_defaultLanguage");
if (defaultLanguageField.getValue() == language) {
Expand Down
6 changes: 6 additions & 0 deletions src/Controller/Admin/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ protected function buildPimcoreSettings(
$config = $templateParams['config'];
$systemSettings = $templateParams['systemSettings'];
$adminSettings = $templateParams['adminSettings'];
$requiredLanguages = $systemSettings['general']['valid_languages'];
$dashboardHelper = new Dashboard($user);
$customAdminEntrypoint = $this->getParameter('pimcore_admin.custom_admin_route_name');

Expand All @@ -206,6 +207,10 @@ protected function buildPimcoreSettings(
$adminEntrypointUrl = null;
}

if (array_key_exists('required_languages', $systemSettings['general'])) {
$requiredLanguages = $systemSettings['general']['required_languages'];
}

$settings = [
'instanceId' => $this->getInstanceId(),
'version' => Version::getVersion(),
Expand All @@ -224,6 +229,7 @@ protected function buildPimcoreSettings(
$systemSettings['general']['valid_languages'],
true
),
'requiredLanguages' => $requiredLanguages,

// flags
'showCloseConfirmation' => true,
Expand Down
6 changes: 6 additions & 0 deletions src/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ public function getSystemAction(Request $request, SystemSettingsConfig $config):
$this->checkPermission('system_settings');
$config = $config->getSystemSettingsConfig();

// If required languages is empty it's the same as if all langauges are required. Therefore, we
// need to overwrite the value with the valid languages value to have all languages required
if (empty($config['general']['required_languages']) === true) {
$config['general']['required_languages'] = $config['general']['valid_languages'];
}

$valueArray = [
'general' => $config['general'],
'documents' => $config['documents'],
Expand Down
1 change: 1 addition & 0 deletions translations/admin_ext.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ classificationstore_error_addcollection_msg: Error adding group
log_search_pid: PID
log_refresh_seconds: Seconds
system_requirements_check: System-Requirements Check
required_language: 'Mandatory language'
rgbaColor: RGBA Color
booleanSelect: Boolean Select
quantityValue: Quantity Value
Expand Down

0 comments on commit c783da2

Please sign in to comment.