Open rogersarrasin opened 4 years ago
@rogersarrasin - I know you and I have discussed this and agree that a hook is not the proper solution, but just for the record here, this does "solve" it:
$this->addHookAfter('Page::references', function(HookEvent $event) {
$referencingPages = $event->return;
$actualPageArr = new PageArray();
foreach($referencingPages as $p) {
if(method_exists($p, 'getForPage')) {
$actualPageArr->add($p->getForPage());
}
else {
$actualPageArr->add($p);
}
}
$event->return = $actualPageArr;
});
Sorry @rogersarrasin - I just realized you are talking about links, not references.
If you change that above hook for Page::links
it should handle calls to $page->links()
and also work for the "What pages link to this page" section.
You could also hook both at once, like this:
$this->addHookAfter('Page::references, Page::hooks', function(HookEvent $event) {
$referencingPages = $event->return;
$actualPageArr = new PageArray();
foreach($referencingPages as $p) {
if(method_exists($p, 'getForPage')) {
$actualPageArr->add($p->getForPage());
}
else {
$actualPageArr->add($p);
}
}
$event->return = $actualPageArr;
});
@adrianbj Thanks for the updated. Seems adding Page::hooks didn't work, but replacing it with Page::links did.
$this->addHookAfter('Page::references, Page::links', function(HookEvent $event) {
$referencingPages = $event->return;
$actualPageArr = new PageArray();
foreach($referencingPages as $p) {
if(method_exists($p, 'getForPage')) {
$actualPageArr->add($p->getForPage());
} else {
$actualPageArr->add($p);
}
}
$event->return = $actualPageArr;
});
Oh my goodness - I don't know how or why I ended up with hooks
instead of links
- brain definitely wasn't firing on all cylinders when I typed that :)
Anyway, glad it worked once you fixed my blunder!
Short description of the issue
When on a website page in the admin area under Settings -> What pages link to this page? Found pages display links but only when links are in pages. If links are in repeater fields it returns a link to the repeater template. Ie. /user/setup/duplicator/for-field-346/for-page-1752/1561680242-0599-1/ (in href link)
Expected behavior
The expected behaviour would be a link to the parent page. Ie. the page that an anonymous user would see when viewing the page. A link to the repeater template doesn't seem too helpful.
Actual behavior
If a link was create in a repeater field, the rendered link under "What pages link to this page?" is a link to the repeater template. ie. Ie. /user/setup/duplicator/for-field-346/for-page-1752/1561680242-0599-1/ (in href link)
Optional: Screenshots/Links that demonstrate the issue
Optional: Suggestion for a possible fix
Sorry, can't suggest a fix. But the behaviour of returning a link to the parent page and not the repeater template if a parent page existed would be much more useful.
Steps to reproduce the issue
Setup/Environment
I've tested on three different sites an have the same results.