You are here

public function GridStackVariant::toUrl in GridStack 8.2

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/GridStackVariant.php, line 109

Class

GridStackVariant
Defines the GridStack variant configuration entity.

Namespace

Drupal\gridstack\Entity

Code

public function toUrl($rel = 'edit-form', array $options = []) {
  $uri = NULL;
  $parameters = [];
  if ($rel === 'add-form' || $rel === 'duplicate-form') {
    $parameters['gridstack'] = $this
      ->getOptionset()
      ->id();
    if ($rel === 'add-form') {
      $uri = new Url("entity.gridstack_variant.add_form", $parameters);
    }
    else {
      $uri = new Url("entity.gridstack_variant.duplicate_form", $parameters);
    }
  }
  if ($rel === 'edit-form' || $rel === 'delete-form') {
    $parameters['gridstack'] = $this
      ->getOptionset()
      ->id();
    $parameters['gridstack_variant'] = $this
      ->id();
    if ($rel === 'edit-form') {
      $uri = new Url("entity.gridstack_variant.edit_form", $parameters);
    }
    else {
      $uri = new Url("entity.gridstack_variant.delete_form", $parameters);
    }
  }
  if ($uri) {
    $options += [
      'language' => NULL,
      'entity_type' => 'gridstack_variant',
      'entity' => $this,
    ];
    $uri
      ->setOptions($options);
    return $uri;
  }
  return parent::toUrl($rel, $options);
}