Fatal error when importing configuration with new facets and view: Call to a member function getDisplay() on null

Created on 9 January 2024, 6 months ago
Updated 10 January 2024, 6 months ago

Problem/Motivation

The \Drupal\facets_exposed_filters\Plugin\facets\url_processor\ViewsExposedFilters gets the information of the view from the facets source plugin. At the same time, the views information from those plugins are generated by a deriver (typically \Drupal\facets\Plugin\facets\facet_source\SearchApiDisplayDeriver) which retrieves the information about the existing views when the cache gets cleared. However, when a new view gets created, the information is not updated at facets source plugin level. As consequence, when importing configuration, and that configuration includes a new view and facets, after creating the view and when the first facet is trying to be created, the following fatal error happens:

 [warning] Attempt to read property "pluginDefinition" on null ViewsExposedFilters.php:85
 [warning] Trying to access array offset on value of type null ViewsExposedFilters.php:85
 [warning] Undefined array key 1 ViewsExposedFilters.php:87
 [warning] Undefined array key 1 ViewsExposedFilters.php:89
Error: Call to a member function getDisplay() on null in /..../web/modules/contrib/facets/modules/facets_exposed_filters/src/Plugin/facets/url_processor/ViewsExposedFilters.php on line 91 #0 /..../web/modules/contrib/facets/modules/facets_exposed_filters/src/Plugin/facets/url_processor/ViewsExposedFilters.php(33): Drupal\facets_exposed_filters\Plugin\facets\url_processor\ViewsExposedFilters->initializeActiveFilters()
#1 /..../web/modules/contrib/facets/modules/facets_exposed_filters/src/Plugin/facets/url_processor/ViewsExposedFilters.php(40): Drupal\facets_exposed_filters\Plugin\facets\url_processor\ViewsExposedFilters->__construct(Array, 'views_exposed_f...', Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Entity\EntityTypeManager))
#2 /..../web/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php(21): Drupal\facets_exposed_filters\Plugin\facets\url_processor\ViewsExposedFilters::create(Object(Drupal\Core\DependencyInjection\Container), Array, 'views_exposed_f...', Array)

Steps to reproduce

- Dump the database
- Create a search_api view
- Create a set of facets
- Add those facets as exposed filters to the new view
- Export the configuration
- Import the database dump
- Run drush cim

Proposed resolution

Once 📌 Allow plugin derivers to specify cacheability (tags, contexts, max-age) for their definitions Postponed: needs info gets fixed, the would be possible for facet source plugins to have a cache tag so they can be invalidated when a new view gets created. Meanwhile, we propose to take the same approach as the group module: Clear the facets source cached definitions when a new view gets created. Note: this could be optimized by checking if the view is a search_api view, but for now we are keeping it simple and clearing the definitions on every view creation.
Example from group module: https://git.drupalcode.org/project/group/-/blob/3.0.x/modules/gnode/gnod...

Remaining tasks

- Patch
- Review
- Test

User interface changes

- None

API changes

- None

Data model changes

- None

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇪🇸Spain akalam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024