Thanks Mike, I try to "chase" the XF2 codebase to try to figure out how it's implemented in the core and try to mimic the core usage in my addon. Your comment helped me narrow down how to implement what I needed to do with highlightedPosts.That class is essentially just a data container, so extension is not really expected.
If you want to pin an additional post, you should probably be doing it through the highlighted posts system, which can be controlled via thread types. (If you really do need to extend the object, then you can also do that by overriding the method in the thread type system.)
applyPostListFilters function is supposed to work. Because I want to remove the hightlighted post from the main post list. Shouldn't the $postList be passed by reference here so I can manipulate it?I'd generally advise against doing this, though you may have very specific reasons to. The reasons to not do it are pretty significant. I know because this is how question solutions were going to work and we kept running into unexpected problems, eventually scrapping the approach entirely. For example, it can cause pagination issues (giving a page that is potentially blank) andcan significantly break the automatic "go to unread" system (or at least cause some very unexpected behaviors). There are probably other issues that I've forgotten about just now. Moving to the approach where the highlighted post is a reference to the original post in position essentially solves all of these issues.Because I want to remove the hightlighted post from the main post list.
Hmm, thank you for the tip, that's interesting. Definitely ran intoI'd generally advise against doing this, though you may have very specific reasons to. The reasons to not do it are pretty significant. I know because this is how question solutions were going to work and we kept running into unexpected problems, eventually scrapping the approach entirely. For example, it can cause pagination issues (giving a page that is potentially blank) andcan significantly break the automatic "go to unread" system (or at least cause some very unexpected behaviors). There are probably other issues that I've forgotten about just now. Moving to the approach where the highlighted post is a reference to the original post in position essentially solves all of these issues.
giving a page that is potentially blank issue and ended up using applyPostListFilters() to filter out the hightlisted post with $postList finder. Is that not what the post list filter is designed for? I am now curious what application applyPostListFilters() is designed to provide.getPostListFilterInput. The code takes different paths depending on whether filters are present. As an example:if ($effectiveOrder == 'post_date' && !$filters)
{
// can only do this if sorting by position
$postList->onPage($page, $perPage);
}
else
{
$postList->limitByPage($page, $perPage);
}
$totalPosts = $filters ? $postList->total() : ($thread->reply_count + 1);
XF\ControllerPlugin\Thread::getPostLink for your case, though this doesn't necessarily override some of the more UI-based issues with how it affects "go to unread"... We use essential cookies to make this site work, and optional cookies to enhance your experience.