Drupal 使用实体查询获取节点的url路径

Drupal 使用实体查询获取节点的url路径,drupal,Drupal,我试图弄清楚如何通过实体查询获得节点的路径。到目前为止,我已经成功地获取了节点的标题,但我似乎找到了一个解决方案,解决了如何获取节点路径/url的问题。这是我的代码示例 $facultyPostings = $query->get('node') ->condition('status', 1, '=') ->condition('type', 'careers')

我试图弄清楚如何通过实体查询获得节点的路径。到目前为止,我已经成功地获取了节点的标题,但我似乎找到了一个解决方案,解决了如何获取节点路径/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;
}

您需要使用Drupal 8 core.services.yml文件中提供的服务。所以在你的循环中你可以使用

//我想这会得到nid的

$nid=$careersNode->get('id')->value

//根据文件,这是正确的

$alias=\Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid)


您使用的是url别名吗?@vishwa是的,如果您使用的是D7,您可以使用drupal_get_path_alias();如果您有节点nid。在D8中,您可以使用服务路径。alias\u manager目前使用D8,我还不太熟悉Drupal,因此无法成为诚实的人。谢谢您的洞察力,我相信我目前使用的是
$careersNode=\u nodeLoad($faculty\u posting\u careers)将加载或获取节点,它将加载节点。