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

Comments

owenbush created an issue. See original summary.

owenbush’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB

Attached is a patch which first checks for a routeObject before passing it to the TitleResolver.

isholgueras’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Status: Needs review » Reviewed & tested by the community

I've tested in in a Drupal 10.3, sharethis version 3.0.2 and #2 fixes the issue. RTBC for me.

  • vladimiraus committed 1e68dcae on 3.0.x
    Issue #3166139 by owenbush, isholgueras: Sometimes there is no route...
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for contribution. Committed. 🍻

  • vladimiraus committed 1e68dcae on 3.1.x
    Issue #3166139 by owenbush, isholgueras: Sometimes there is no route...

Status: Fixed » Closed (fixed)

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