georgringer / news_filter

Filter news
Other
5 stars 12 forks source link

Losing filter data on page browsing #14

Open baggyownz opened 1 year ago

baggyownz commented 1 year ago

Hi, I think there is a problem in combination with the pagebrowser (numbered_pagination). The filter works fine at first page. But at the second page it lost all data. Is there a solution?

System: TYPO3 10.4.36 News 10.0.3 News_filter 2.0.0

thx

klodeckl commented 1 year ago

Same here. I have a jquery solution:

$("ul.pagination a").click(function (e) { e.preventDefault(); $("form.news-searchform input[name='tx_news_pi1[currentPage]']").val($(this).data('pagenumber')); $('form.news-searchform').submit(); });

And you need a hidden input field:

fgerlesberger commented 1 year ago

Hi,

i have the same problem and this solution doesn't work for me.

Is there another way to fix this issue?

thx

cepheiVV commented 9 months ago

The solution for this would be to store the selected filters in a session. Probably here /Classes/EventListener/NewsListActionEventListener.php in the __invoke method.

$search = GeneralUtility::makeInstance(Search::class);

Here, we need to check if we already have a filter in the session. And if so, we need to use it instead of invoking a new empty "Search" filter.

// Load filter from session or create a new empty search
$request = $event->getRequest();
$frontendUser = $request->getAttribute('frontend.user');
$sessionFilter = $frontendUser->getKey('ses', 'tx_news_filter');
if ($sessionFilter) {
    $sessionFilter = unserialize($sessionFilter);
    $search = $this->propertyMapper->convert($sessionFilter, Search::class);
} else {
    $search = GeneralUtility::makeInstance(Search::class);
}

// set a new search if a new search was submitted
$vars = GeneralUtility::_POST('tx_news_pi1');
if (isset($vars['search']) && is_array($vars['search'])) {

    // serialize and save search in session
    $sessionData = serialize($vars['search']);
    $frontendUser->setKey('ses', 'tx_news_filter', $sessionData);

    /** @var Search $search */
    $search = $this->propertyMapper->convert($vars['search'], Search::class);
}

However, this only handles the ext.news_filter part to keep the Search class for the filter when reloading the page. For ext.news to also load the news by this session filter, we would need to set up the createDemandObjectFromSettings hook and set our session filter to the demand: https://docs.typo3.org/p/georgringer/news/main/en-us/Tutorials/ExtendNews/Demands/Index.html#hook-createdemandobjectfromsettings

There's a method createDemandObjectFromSettings in /Classes/EventListener/NewsListActionEventListener.php that could maybe be used to set the demand from the session. But it looks like dead code to me, since this method is never called anywhere. Probably replaced by \GeorgRinger\NewsFilter\Hooks\EnrichDemandObject->run.

cepheiVV commented 9 months ago

I made PR #19 to solve this problem. It works fine in my v11 project.

klodeckl commented 9 months ago

@cepheiVV why do you want to store it in the session and not in form parameters?

cepheiVV commented 9 months ago

Beause we ain't got no form in paginated links. @klodeckl

Also, you're missing the point with your jQuery solution. It's not about passing the current currentPage parameter, but rather storing filtered categories, tags and text-search queries.

klodeckl commented 9 months ago

@cepheiVV Ah, sorry, you’re right. :)

pitscribble commented 8 months ago

The patch does not work for me, unfortunately. It keeps the selection when using the pagination links, like it should. But for instance if I select 2 categories and then switch to page 5 and then open the same site in another browser and got to page 5 it has the selection of the first browser there, too.

cyril392 commented 6 months ago

same problem here TYPO3 12.4.14 and news-fitler 2.1.0. First page is good but lost all data after