diff --git a/CHANGES.rst b/CHANGES.rst index 856f012a..f5455a27 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,10 @@ New features: Bug fixes: +- Don't acquire lanuage from portal root default_language for ICategorization.language. + Fixes https://github.com/plone/plone.app.dexterity/issues/258 + [jaroel] + - Make sure robot autologin test fixture is not accidentally torn down when the Dexterity fixture's ZODB sandbox is reverted. [davisagli] diff --git a/plone/app/dexterity/behaviors/metadata.py b/plone/app/dexterity/behaviors/metadata.py index 13df017b..54b28493 100644 --- a/plone/app/dexterity/behaviors/metadata.py +++ b/plone/app/dexterity/behaviors/metadata.py @@ -41,22 +41,27 @@ def default_language(context): # this new content is being added language = None - if context is not None and not IPloneSiteRoot.providedBy(context): - language = context.Language() - if not language: + # Try to get the language from context or parent(s) + while context is not None and not IPloneSiteRoot.providedBy(context): + try: + # Use aq_base so the .language attribute isn't acquired from root + language = context.aq_base.Language() + except AttributeError: # Accesses .language # If we are here, it means we were editing an object that didn't # have its language set or that the container where we were adding # the new content didn't have a language set. So we check its - # parent, unless we are at site's root, in which case we get site's - # default language - if not IPloneSiteRoot.providedBy(context.aq_parent): - language = context.aq_parent.Language() + # parent. + context = context.__parent__ + + pl = getToolByName(getSite(), 'portal_languages') + default_language = pl.getDefaultLanguage() if not language: - # Finally, if we still don't have a language, then just use site's - # default - pl = getToolByName(getSite(), 'portal_languages') - language = pl.getDefaultLanguage() + language = default_language + + # Is the language supported/enabled at all? + if language not in pl.getAvailableLanguages(): + language = default_language return language