Problem/Motivation
Under some circumstances there is no route object to pass through to TitleResolver::getTitle(), which causes the following error:
TypeError: Argument 2 passed to Drupal\Core\Controller\TitleResolver::getTitle() must be an instance of Symfony\Component\Routing\Route, null given, called in /var/www/html/domain.com/docroot/modules/contrib/sharethis/src/Plugin/Block/SharethisWidgetBlock.php on line 159 in Drupal\Core\Controller\TitleResolver->getTitle() (line 50 of /var/www/html/domain.com/docroot/core/lib/Drupal/Core/Controller/TitleResolver.php).
The problem here is that there is an assumption that there is an active route in the request, but we have found that when we indexed the rendered HTML of entities using Search API via Cron, there is no active route.
Steps to reproduce
1. Create an entity or content type with share this functionality
2. Create a solr/elasticsearch/whatever index using Search API
3. Add rendered_item as an indexed field for the content type you have configured
4. Install ultimate cron
5. Set up cron to run via drush
6. Let cron run naturally
7. Check the Search API cron task in ultimate cron for errors
8. You should see the issue above.
Proposed resolution
Check that $this->routeMatch->getRouteObject(); in ShareThisManager.php and ShareThisWidgetBlock.php actually has a value before passing it to $this->titleResolver->getTitle().
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | sharethis-getTitle_null_route_object-3166139-2.patch | 1.69 KB | owenbush |
Comments
Comment #2
owenbush commentedAttached is a patch which first checks for a routeObject before passing it to the TitleResolver.
Comment #3
isholgueras commentedI've tested in in a Drupal 10.3, sharethis version 3.0.2 and #2 fixes the issue. RTBC for me.
Comment #5
vladimirausThank you for contribution. Committed. 🍻