Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Testing whether some rest endpoint work we ran into empty result for at least
curl --verbose --user admin:admin --header 'Accept: application/json' --request GET http://drupal.d8/taxonomy_vocabulary/term/1
{}
Running script drush @drupal.d8 php-script routes.php
or inspect the route tabel
// route.php
$routes = db_query('select * from router');
foreach($routes as $route) {
$route->route = unserialize($route->route);
if (strpos($route->name, 'rest') !== 0) continue;
echo "$route->name\t$route->path" . PHP_EOL;
print_r($route);
}
shows the _content is replaced from [_controller] => Drupal\rest\RequestHandler::handle
to [_content] => Drupal\views\Routing\ViewPageController::handle
stdClass Object
(
[name] => rest.entity.taxonomy_term.GET.json
[path] => /taxonomy/term/{taxonomy_term}
[pattern_outline] => /taxonomy/term/%
[fit] => 6
[route] => Symfony\Component\Routing\Route Object
(
[path:Symfony\Component\Routing\Route:private] => /taxonomy/term/{taxonomy_term}
[host:Symfony\Component\Routing\Route:private] =>
[schemes:Symfony\Component\Routing\Route:private] => Array
(
)
[methods:Symfony\Component\Routing\Route:private] => Array
(
)
[defaults:Symfony\Component\Routing\Route:private] => Array
(
[view_id] => taxonomy_term
[display_id] => page_1
[_content] => Drupal\views\Routing\ViewPageController::handle
)
[requirements:Symfony\Component\Routing\Route:private] => Array
(
[_access] => TRUE
)
[options:Symfony\Component\Routing\Route:private] => Array
(
[compiler_class] => \Drupal\Core\Routing\RouteCompiler
[_access_mode] => ANY
[_view_argument_map] => Array
(
[arg_0] => taxonomy_term
)
[parameters] => Array
(
[taxonomy_term] => Array
(
[type] => entity:taxonomy_term
[converter] => paramconverter.entity
)
)
class \Drupal\views\EventSubscriber\RouteSubscriber
...
protected function alterRoutes(RouteCollection $collection) {
is in error assuming it should take over the json response. But the current view does not have a 'Rest export' display.
Proposed resolution
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#2 | view_rest-2344129-2.patch | 14.26 KB | dawehner |
Comments
Comment #1
dawehnerI see, so views should take care about the
_accept
option. Myabe we need some logic to override existingjson ones, in case we provide a rest display.
Comment #2
dawehnerWorked on some patch offline. This should get a regression test as well.
Comment #5
swentel CreditAttribution: swentel at eps & kaas commentedI guess it's safe to close this in favor of #2449143: REST views specify HTML as a possible request format, so if there is a "regular" HTML view on the same path, it will serve JSON ?