Sometimes there is no route object to pass to TitleResolver::getTitle()

Created on 19 August 2020, over 4 years ago
Updated 20 December 2024, about 1 month ago

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

πŸ› Bug report
Status

RTBC

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024