When indexing an entity that is containing a rendered view mode results in a fatal error, when the view mode renders the breadcrumb in the template by e.g. using Twig tweak.

When running drush sapi-i you get the following error:

>  [error]  InvalidArgumentException while trying to render item entity:node/95:nl with view mode full for search index Elasticsearch: Route required in Drupal\Core\Url::fromRouteMatch() (line 159 of /vagrant/htdocs/web/core/lib/Drupal/Core/Url.php). 

Modules using:

Steps to reproduce:

  1. Create a custom node with a custom template e.g. node--page.html.twig
  2. In the custom template print the following twig statement: {{- drupal_breadcrumb() -}} (this twig function is provided by Twig Tweak.
  3. Create a Search API index.
  4. Add "Rendered item" as field in your index. As view mode, choose the view mode containing the drupal_breadcrumb() statement.
  5. Run drush sapi-i
  6. You now get the InvalidArgumentException error.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JeroenT created an issue. See original summary.

JeroenT’s picture

Issue summary: View changes
JeroenT’s picture

Issue summary: View changes
JeroenT’s picture

Status: Active » Needs review
FileSize
719 bytes
jrockowitz’s picture

Using \Drupal::service('path.current')->getPath(); is going to be unpredictable via CLI. Instead let's make sure the route match object exists.

jrockowitz’s picture

Status: Needs review » Fixed

  • jrockowitz authored 92e2e92 on 8.x-5.x
    Issue #3101533 by JeroenT, jrockowitz: Indexing a rendered entity which...
JeroenT’s picture

Thanks. Patch is working as expected.

Status: Fixed » Closed (fixed)

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