Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Losing filter data on page browsing #14

Open
baggyownz opened this issue Mar 8, 2023 · 10 comments
Open

Losing filter data on page browsing #14

baggyownz opened this issue Mar 8, 2023 · 10 comments

Comments

@baggyownz
Copy link

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
Copy link

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
Copy link

Hi,

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

Is there another way to fix this issue?

thx

@cepheiVV
Copy link

cepheiVV commented Feb 11, 2024

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
Copy link

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

@klodeckl
Copy link

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

@cepheiVV
Copy link

cepheiVV commented Feb 11, 2024

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
Copy link

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

@pitscribble
Copy link

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
Copy link

cyril392 commented May 3, 2024

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

@ashupatel1990
Copy link

ashupatel1990 commented Dec 9, 2024

In TYPO3 12, I have fixed issue by taking value of filteredCategory in one session custom key with pagination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants