//TODO: Tim? why does the above evaluate true, breaking the form?
// and more importantly, if this is a valid situation, how should we react,
// that is, what does this mean?
//$mform->hardFreeze('parent');
"By the way, the purpose of the code
if (1 == $DB->count_records_sql("SELECT count
FROM
{question_categories}
c2
WHERE c2.id = ?
AND c1.contextid = c2.contextid", array($currentcat)))
Well, the SQL is counting the number of other categories belonging to the same context as this one. If there is only one, then it is trying to stop you changing the parent (so you can't remove the default category from any context.) However, that should not apply when you are creating a new context. (That applies to the standard create category form too.) Can you either fix this, or create a new issues assigned to me."
If the check does not apply, perhaps remove it, or debug the reason behind it?