protected function validate_field(field_controller $field) : field_controller {
        if (!array_key_exists($field->get('categoryid'), $this->get_categories_with_fields())) {
            throw new \moodle_exception('fieldnotfound', 'core_customfield');
        }
        $category = $this->get_categories_with_fields()[$field->get('categoryid')];
        if (!array_key_exists($field->get('id'), $category->get_fields())) {
            throw new \moodle_exception('fieldnotfound', 'core_customfield');
        }
        return $category->get_fields()[$field->get('id')];
    }