Problem/Motivation

Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\views_autocomplete_api\Service\ViewsAutocompleteApiManager->getViewsDisplayId() (regel 95 van /app/web/modules/contrib/views_autocomplete_api/src/Service/ViewsAutocompleteApiManager.php)

The argument $count_view passed to getViewsDisplayId() must be an int, on line 95 the function count is applied to $count_view which lead to a php warning. The use of count() has no needed.

Steps to reproduce

Open a url like /admin/view_content/view_autocomplete_search_all?q=pen and inspect /admin/reports/dblog

Proposed resolution

Remove the count function applied to $count_view

(First patch contains a bug added views_autocomplete_api-3.patch)

CommentFileSizeAuthor
#3 views_autocomplete_api-3.patch877 bytes4p
views_autocomplete_api-2.patch878 bytes4p

Comments

4p created an issue. See original summary.

4p’s picture

Status: Needs review » Closed (outdated)
4p’s picture

Issue summary: View changes
StatusFileSize
new877 bytes
4p’s picture

Status: Closed (outdated) » Needs review
brolad’s picture

#3 solved the issue, thanks for the patch. But I guess we should contain all the logic inside the ViewsAutocompleteApiManager.php file. I mean we should remove the count() from ViewsAutocompleteApiController.php that passes to methods getViewsDisplayId() & prepareArgumentViews() and replace these methods to accept array type and make it compatible with providing count() and other expecting logic. What do you think?

trevorbradley’s picture

Reviewed and working.

Note that in PHP 8.1, this isn't a warning, it's an error that broke my site. #3 patches the issue and my AJAX call is working again.

trevorbradley’s picture

Status: Needs review » Reviewed & tested by the community
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for your contributions. 🎂
Committed. 🚀

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • vladimiraus committed 1be42bc5 on 2.1.x
    [#3257194] fix: Fix php warning in ViewsAutocompleteApiManager.php
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.