Ported fix for https://dev.plone.org/ticket/13833 from the 1.9.x branch