drupal 8 get url from node entity
$entity->toUrl()->toString();
Here is what the above code is Doing:
1. We’re using the `getEntity()` method to get the entity object for the current page.
2. We’re using the `toUrl()` method to get the URL object for the current page.
3. We’re using the `toString()` method to get the string representation of the URL object.
The `toString()` method is a method that is available on all objects in Drupal 8. It returns a string representation of the object.
## Using the `toLink()` method
The `toLink()` method is a method that is available on all URL objects in Drupal 8. It returns a link object.
Here’s an example of how to use the `toLink()` method: