protected function addNewFact(ServerRequestInterface $request, Tree $tree, $fact): string
    {
        $FACT = $request->get($fact, '');
        $DATE = $request->get($fact . '_DATE', '');
        $PLAC = $request->get($fact . '_PLAC', '');
        if ($DATE !== '' || $PLAC !== '' || $FACT !== '' && $FACT !== 'Y') {
            if ($FACT !== '' && $FACT !== 'Y') {
                $gedrec = "\n1 " . $fact . ' ' . $FACT;
            } else {
                $gedrec = "\n1 " . $fact;
            }
            if ($DATE) {
                $gedrec .= "\n2 DATE " . $DATE;
            }
            if ($PLAC) {
                $gedrec .= "\n2 PLAC " . $PLAC;

                if (preg_match_all('/(' . Gedcom::REGEX_TAG . ')/', $tree->getPreference('ADVANCED_PLAC_FACTS'), $match)) {
                    foreach ($match[1] as $tag) {
                        $TAG = $request->get($fact . '_' . $tag, '');
                        if ($TAG !== '') {
                            $gedrec .= "\n3 " . $tag . ' ' . $TAG;
                        }
                    }
                }
                $LATI = $request->get($fact . '_LATI', '');
                $LONG = $request->get($fact . '_LONG', '');
                if ($LATI !== '' || $LONG !== '') {
                    $gedrec .= "\n3 MAP\n4 LATI " . $LATI . "\n4 LONG " . $LONG;
                }
            }
            if ((bool) $request->get('SOUR_' . $fact)) {
                return $this->updateSource($gedrec, 2);
            }

            return $gedrec;
        }

        if ($FACT === 'Y') {
            if ((bool) $request->get('SOUR_' . $fact)) {
                return $this->updateSource("\n1 " . $fact . ' Y', 2);
            }

            return "\n1 " . $fact . ' Y';
        }

        return '';
    }