public function instance_config_save($data, $nolongerused = false) {
        global $DB;
        if (empty($data->activitygradeitemid)) {
            // Figure out info about parent module.
            $info = $this->get_owning_activity();
            $data->activitygradeitemid = $info->id;
            if ($info->id < 1) {
                // No activity was selected.
                $info->itemmodule = '';
                $info->iteminstance = '';
            } else {
                $data->activityparent = $info->itemmodule;
                $data->activityparentid = $info->iteminstance;
            }
        } else {
            // Lookup info about the parent module (we have the id from mdl_grade_items.
            $info = $DB->get_record('grade_items', array('id' => $data->activitygradeitemid));
            $data->activityparent = $info->itemmodule;
            $data->activityparentid = $info->iteminstance;
        }
        parent::instance_config_save($data);
    }