webtrees icon indicating copy to clipboard operation
webtrees copied to clipboard

GedcomRecordPage check for standard records is problematic

Open ric2016 opened this issue 2 years ago • 5 comments

The 'in_array' check doesn't account for custom records replacing the standard records (not even subclasses work):

If I use e.g. a custom individual record via IndividualFactoryInterface, this check doesn't detect that.

Result is that links e.g. from the error report aren't redirected to the normal individual page, and end up on a generic edit-record page.

ric2016 avatar May 06 '22 17:05 ric2016

Perhaps just replace the entire check (including the xref part), i.e. lines 94-96 with this:

$genericRecord = Registry::gedcomRecordFactory()->new($xref, '', null, $tree);
if ($record->url() !== $genericRecord->url()) {
    return redirect($record->url());
}

(or some equivalent check to determine whether it's a generic record, or a record created by a specific factory)

ric2016 avatar May 07 '22 19:05 ric2016

Would it work for you if we had this:

if ($record instanceof XXX || $record instanceof YYY || ...) {
  redirect...
}

fisharebest avatar May 07 '22 22:05 fisharebest

That would work as well, as custom factories always return subclasses of the respective type (I assumed above they could return any subclass of GedcomRecord, but that's not the case).

ric2016 avatar May 08 '22 06:05 ric2016

~~How about~~

~~if ($record instanceof GedcomRecord && get_class($record) !== GedcomRecord::class) { redirect }~~

~~This should handle all sub-classes.~~

No, this wouldn't work. Need more coffee before I start coding :-)

fisharebest avatar May 08 '22 06:05 fisharebest

There could be custom record types that we do not know about.

I think your original idea using URLs might be better. Something like:

if ($record->url() !== $request->url()) {}

fisharebest avatar May 08 '22 07:05 fisharebest