Task: to retrieve a list of nodes in JSON format including their aliases generated by Pathauto module. The configuration of my view is this:
Problem: path fields come empty - they won't include original Drupal path to it nor an alias generated by Pathauto:
The current solution I've got is to programmatically amend view's result in the following way:
function my_custom_views_pre_render(\Drupal\views\ViewExecutable $view) {
foreach($view->result as $value) {
$url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $value->_entity->get('nid')->value], ['absolute' => false]);
$url = $url->toString();
$value->_entity->set('path', $url);
}
}
And that populates the path fields:
I'd like to know if there is a way to avoid the hook and make views return node paths without it, or is it normal Drupal Views behaviour?
P.s.: If I chose "Fields" instead of "Entity" in the Format section in the Views UI, it does return me the correct paths. However I want to get the full entity due to extensive data it consists for later consumption. Thanks!