我试图找出如何通过实体查询获取节点的路径。到目前为止,我已经设法获取节点的标题,但我似乎找到了如何获取节点路径/ 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;
}
答案 0 :(得分:2)
您需要使用Drupal 8 core.services.yml文件中提供的服务。所以在循环中你可以使用。
//认为这样会得到nid
$ nid = $ careersNode-> get('id') - > value;
//根据文档
,这个是正确的$ alias = \ Drupal :: service('path.alias_manager') - > getAliasByPath('/ node /'.$ nid);