Extract Url & Title from link field in Drupal 8?

后端 未结 11 662
一生所求
一生所求 2021-01-31 05:29

I\'m trying to retrieve the URL and the Title values of a Link field in Drupal 8.

In my custom controller, I retrieve the nodes with:<

11条回答
  •  执念已碎
    2021-01-31 05:57

    Just to piggyback on the above, if you have an external link,

    $node->field_name->uri
    

    Will give you the URL, but if it's an internal you may need to tweak a bit more:

    use Drupal\Core\Url;
    
    $mylink = Url::fromUri($node->field_name[0]->uri);
    $mylink->toString();
    

提交回复
热议问题