Problem/Motivation

Give a $entity, how to generate the API-path of it?

'/ce-api/' . $entity->toUrl() works but is not exactly nice or flexible.
/ce-api might change, and integration modules might alter the API for a given $entity in a multi-frontend scenariou.

Proposed resolution

$entity->toUrl('canonical', ['ce_api' => TRUE]
or
$entity->toUrl('canonical', ['_format' => 'custom_elements']

Comments

fago created an issue. See original summary.

fago’s picture

Title: Define API for getting ce-api URL » Introduce API for getting the /ce-api URL
fago’s picture

Issue summary: View changes
useernamee’s picture

I checked into this issue and did not find a nice way to hook into the toUrl method https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

Maybe I wasn't thorough enough but $options parameter on UrlGeneratorInterface seem to be defined in advance: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Routing%2...