Null title when indexing rendered content

Created on 6 April 2023, about 1 year ago
Updated 21 April 2023, about 1 year ago

* Place the Better Social Sharing Button block onto a page (in my case I added the block to the default layout of a content type)
* Use Search API module to index content
* Add the Rendered Item field to the search index to allow it to index the entire rendered page, including the social sharing block
* During indexing, will get an error in the log:

Deprecated function: rawurlencode(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\UrlHelper::encodePath() 

This comes from the following code in src/Plugin/Block/SocialSharingButtonsBlock.php:

    if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
      $title = $this->titleResolver->getTitle($request, $route);
    }

This returns an empty $title because the $route is actually /batch from the search api indexing job, rather that the route of the node.

Not sure the best way to patch this, but was thinking of changing

    $items['title'] = UrlHelper::encodePath($title);

to

    $items['title'] = !empty($title) ? UrlHelper::encodePath($title) : '';

I know this is a pretty obscure error. I'll post a patch with this workaround.

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mpotter

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

Comments & Activities

Production build 0.69.0 2024