You are here

public function EntityExtraField::toUrl in Entity Extra Field 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/EntityExtraField.php \Drupal\entity_extra_field\Entity\EntityExtraField::toUrl()

Gets the URL object for the entity.

The entity must have an id already. Content entities usually get their IDs by saving them.

URI templates might be set in the links array in an annotation, for example:


links = {
  "canonical" = "/node/{node}",
  "edit-form" = "/node/{node}/edit",
  "version-history" = "/node/{node}/revisions"
}

or specified in a callback function set like:


uri_callback = "comment_uri",

If the path is not set in the links array, the uri_callback function is used for setting the path. If this does not exist and the link relationship type is canonical, the path is set using the default template: entity/entityType/id.

Parameters

string $rel: The link relationship type, for example: canonical or edit-form.

array $options: See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return value

\Drupal\Core\Url The URL object.

Throws

\Drupal\Core\Entity\EntityMalformedException

\Drupal\Core\Entity\Exception\UndefinedLinkTemplateException

Overrides ConfigEntityBase::toUrl

File

src/Entity/EntityExtraField.php, line 347

Class

EntityExtraField
Define entity extra field.

Namespace

Drupal\entity_extra_field\Entity

Code

public function toUrl($rel = 'edit-form', array $options = []) {
  $base_route_name = $this
    ->getBaseRouteName();
  $route_parameters = $this
    ->urlRouteParameters($rel);
  switch ($rel) {
    case 'collection':
      return URL::fromRoute($base_route_name, $route_parameters, $options);
    case 'add-form':
      return Url::fromRoute("{$base_route_name}.add", $route_parameters, $options);
    case 'edit-form':
      return Url::fromRoute("{$base_route_name}.edit", $route_parameters, $options);
    case 'delete-form':
      return Url::fromRoute("{$base_route_name}.delete", $route_parameters, $options);
  }
  throw new \RuntimeException(sprintf('Unable to find %s to built a URL.', $rel));
}