Skip to content

Commit

Permalink
Don't acquire .language from portal root.
Browse files Browse the repository at this point in the history
  • Loading branch information
agitator committed May 9, 2022
1 parent 7b5fe0f commit 9ff07c6
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions plone/app/dexterity/behaviors/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,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

Expand Down

0 comments on commit 9ff07c6

Please sign in to comment.