我正在尝试弄清楚如何通过实体查询获取节点的路径。到目前为止,我已经设法获取了节点的标题,但我似乎找到了如何获取节点路径/url的解决方案。以下是我的代码示例
$facultyPostings = $query->get('node')
->condition('status', 1, '=')
->condition('type', 'careers')
->condition('field_career_directory', 'Faculty Postings', '=')
->sort('created')
->execute();
foreach ($facultyPostings as $key => $faculty_postings_careers) {
$careersNode = _nodeLoad($faculty_postings_careers);
$variables['faculty_postings'][$key]['title'] = $careersNode->get('title')->value;
$variables['faculty_postings'][$key]['path'] = $careersNode->get('path')->value;
}发布于 2017-07-25 16:36:09
您需要使用Drupal8 core.services.yml文件中提供的服务。所以在你的循环中你可以使用。
//我是这么想的,这将获得nid
$nid = $careersNode->get('id')->value;
//根据文档,这一条是正确的
$alias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid);
https://stackoverflow.com/questions/45233136
复制相似问题