drupal-graphql / drupal-graphql/graphql

[4.x] RouteEntity Producer doesn't support views which have a path

Open
#1,270 0 comments 0 reactions 0 assignees View on GitHub
4.x bug
Dominant language
PHP
Stars
287
Forks
198
PR merge metrics
No merged PRs in 30d

Description

The `RouteEntity` producer currently only works with entities with route name of format `anything.TYPE_NAME.anything`.
Code which shows that (RouteEntity.php):
```php
[, $type] = explode('.', $url->getRouteName());
$parameters = $url->getRouteParameters();
$id = $parameters[$type];
$resolver = $this->entityBuffer->add($type, $id);
```

This does not work with views which have a path assigned, because views have the following routename format: `view.VIEW_ID.PAGE_ID`.
When you use the RouteEntity producer on a path which translates to a view, it will throw an error:
```
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "__SOME_VIEW_ID__" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (Line 143 in /docroot/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
```

There should be a check implemented for `entity / view`. Something like this:

```php
[$baseType, $type] = explode('.', $url->getRouteName());

if ($baseType === 'entity') {
$parameters = $url->getRouteParameters();
$id = $parameters[$type];
} else if ($baseType === 'view') {
// View routeNames have format 'view.VIEW_ID.PAGE_ID'
$id = $type;
$type = 'view';
} else {
return NULL;
}

$resolver = $this->entityBuffer->add($type, $id);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.