首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用实体查询获取节点的url路径

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

Stack Overflow用户
提问于 2017-07-21 16:46:00
回答 1查看 1.3K关注 0票数 1

我正在尝试弄清楚如何通过实体查询获取节点的路径。到目前为止,我已经设法获取了节点的标题,但我似乎找到了如何获取节点路径/url的解决方案。以下是我的代码示例

代码语言:javascript
复制
$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;
}
EN

回答 1

Stack Overflow用户

发布于 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://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Path%21AliasManager.php/class/AliasManager/8.3.x

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45233136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档