imported original patch from https://drupal.org/files/issues/1796606_18.patch