1. Could you live with a shorter table whose length is the size of the opening? Then it could just drop down with legs folded behind it.
2. Mount the rear section on full extension slides and fold the front section back on top of it, legs up, folded flat. This would keep the extended table sections at same level. Use a piano hinge between the folding sections.
3. Like 2 except that instead of full extension hardware, hinge the back of the table to the front of the case shelf. Front section folds on top of second section and they both pivot upward so folded legs are inside. Consider what happens when unfolding. Second section with unfolded outer one is going to be heavy (and hard on) on the hinge at the cabinet face. There would have to be a “lock” to keep the second hinge from sagging.
Interesting challenge. Good luck. Keep posting pics.
DanK
-- Dan Krager, Olney IL http://www.kragerwoodworking.weebly.com