Fixing #8787

Applying original patch for https://dev.plone.org/ticket/8787