public function set_handler(handler $handler) {
        // Make sure there are no conflicts.
        if ($this->get('component') !== $handler->get_component()) {
            throw new \coding_exception('Component of the handler does not match the one from the record');
        }
        if ($this->get('area') !== $handler->get_area()) {
            throw new \coding_exception('Area of the handler does not match the one from the record');
        }
        if ($this->get('itemid') != $handler->get_itemid()) {
            throw new \coding_exception('Itemid of the handler does not match the one from the record');
        }
        if ($this->get('contextid') != $handler->get_configuration_context()->id) {
            throw new \coding_exception('Context of the handler does not match the one from the record');
        }
        $this->handler = $handler;
    }