public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_controller {
        global $DB;
        if ($id && $record) {
            // This warning really should be in persistent as well.
            debugging('Too many parameters, either id need to be specified or a record, but not both.',
                DEBUG_DEVELOPER);
        }
        if ($id) {
            if (!$record = $DB->get_record(category::TABLE, array('id' => $id), '*', IGNORE_MISSING)) {
                throw new \moodle_exception('categorynotfound', 'core_customfield');
            }
        }
        if (empty($record->component)) {
            if (!$handler) {
                throw new \coding_exception('Not enough parameters to initialise category_controller - unknown component');
            }
            $record->component = $handler->get_component();
        }
        if (empty($record->area)) {
            if (!$handler) {
                throw new \coding_exception('Not enough parameters to initialise category_controller - unknown area');
            }
            $record->area = $handler->get_area();
        }
        if (!isset($record->itemid)) {
            if (!$handler) {
                throw new \coding_exception('Not enough parameters to initialise category_controller - unknown itemid');
            }
            $record->itemid = $handler->get_itemid();
        }
        $category = new self(0, $record);
        if (!$category->get('contextid')) {
            // If contextid was not present in the record we can find it out from the handler.
            $handlernew = $handler ?? $category->get_handler();
            $category->set('contextid', $handlernew->get_configuration_context()->id);
        }
        if ($handler) {
            $category->set_handler($handler);
        }
        return $category;
    }