mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +08:00
Avoid SingleTermId being null if at least one term is checked (#8662)
* If no term with the proper culture is found, SingleTermId is the id of the first valid checked term. * Correction on firstTermForCulture query if there is no LocalizationPart. Simplified query to check selected terms.
This commit is contained in:
committed by
GitHub
parent
2dd08dbc04
commit
4455c66a64
@@ -64,10 +64,17 @@ namespace Orchard.Taxonomies.Controllers {
|
||||
|
||||
// It takes the first term localized with the culture in order to set correctly the TaxonomyFieldViewModel.SingleTermId
|
||||
var firstTermForCulture = appliedTerms.FirstOrDefault(x => x.As<LocalizationPart>() != null && x.As<LocalizationPart>().Culture != null && x.As<LocalizationPart>().Culture.Culture == culture);
|
||||
if (firstTermForCulture != null) {
|
||||
firstTermIdForCulture = firstTermForCulture.Id;
|
||||
} else {
|
||||
// If there is no valid localization, firstTermForCulture is null.
|
||||
// To avoid that, use the first checked term (if any is checked).
|
||||
firstTermForCulture = appliedTerms.FirstOrDefault(t => terms.Any(x => x.Id == t.Id));
|
||||
if (firstTermForCulture != null) {
|
||||
firstTermIdForCulture = firstTermForCulture.Id;
|
||||
}
|
||||
terms.ForEach(t => t.IsChecked = appliedTerms.Select(x => x.Id).Contains(t.Id));
|
||||
}
|
||||
terms.ForEach(t => t.IsChecked = appliedTerms.Any(x => x.Id == t.Id));
|
||||
}
|
||||
viewModel = new TaxonomyFieldViewModel {
|
||||
DisplayName = taxonomyField.DisplayName,
|
||||
|
||||
Reference in New Issue
Block a user