Move disabling code to addOptionItem. Fix disabling logic in checkbox menu items and template. Fixes #17399.

(cherry picked from commit ead78ed67c4ee46c953adf95d72a63acbcc945b8)