public static function save_definitions($areas) {
        $params = self::validate_parameters(self::save_definitions_parameters(),
                                            array('areas' => $areas));

        foreach ($params['areas'] as $area) {

            $context = context::instance_by_id($area['contextid']);
            require_capability('moodle/grade:managegradingforms', $context);
            $gradingmanager = get_grading_manager($context, $area['component'], $area['areaname']);
            $gradingmanager->set_active_method($area['activemethod']);
            $availablemethods = $gradingmanager->get_available_methods();

            foreach ($area['definitions'] as $definition) {
                if (array_key_exists($definition['method'], $availablemethods)) {
                    $controller = $gradingmanager->get_controller($definition['method']);
                    $controller->update_definition(self::create_definition_object($definition));
                } else {
                    throw new invalid_parameter_exception('Unknown Grading method: '. $definition['method']);
                }
            }
        }
    }