Use macros to ensure that `text`, `xl_text` and `id` are always set
using the same logic.
Fixes #25519.
Also fixes up #26914 when `p_id == -1` handling was only added for a
couple methods instead of all of them.
(cherry picked from commit 58dd5d0c78)