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:
- Create a custom node with a custom template e.g. node--page.html.twig
- In the custom template print the following twig statement:
{{- drupal_breadcrumb() -}}(this twig function is provided by Twig Tweak. - Create a Search API index.
- Add "Rendered item" as field in your index. As view mode, choose the view mode containing the drupal_breadcrumb() statement.
- Run drush sapi-i
- You now get the InvalidArgumentException error.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3101533-5.patch | 756 bytes | jrockowitz |
| #4 | 3101533-4.patch | 719 bytes | jeroent |
Comments
Comment #2
jeroentComment #3
jeroentComment #4
jeroentComment #5
jrockowitz commentedUsing
\Drupal::service('path.current')->getPath();is going to be unpredictable via CLI. Instead let's make sure the route match object exists.Comment #6
jrockowitz commentedComment #8
jeroentThanks. Patch is working as expected.