LPS-52136

This logic is nearly identical to that of [LPS-51509](https://github.com/brianchandotcom/liferay-plugins/pull/3997)