Fixed #19617 -- Refactored form metaclasses to support more inheritance scenarios.

**Work in progress, not RFC**.