Commit 9c4bc86c authored by catch's avatar catch
Browse files

Issue #3371753 by tstoeckler, smustgrave, lauriii: Fall back to 'edit-form' as...

Issue #3371753 by tstoeckler, smustgrave, lauriii: Fall back to 'edit-form' as default $rel in EntityBase::toUrl()
parent e0116bc9
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -395,7 +395,7 @@ public function calculateDependencies() {
  /**
   * {@inheritdoc}
   */
  public function toUrl($rel = 'edit-form', array $options = []) {
  public function toUrl($rel = NULL, array $options = []) {
    // Unless language was already provided, avoid setting an explicit language.
    $options += ['language' => NULL];
    return parent::toUrl($rel, $options);
+14 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ public function label() {
  /**
   * {@inheritdoc}
   */
  public function toUrl($rel = 'canonical', array $options = []) {
  public function toUrl($rel = NULL, array $options = []) {
    if ($this->id() === NULL) {
      throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId()));
    }
@@ -164,6 +164,19 @@ public function toUrl($rel = 'canonical', array $options = []) {
    // The links array might contain URI templates set in annotations.
    $link_templates = $this->linkTemplates();

    // Use the canonical link template by default, or edit-form if there is not
    // a canonical one.
    if ($rel === NULL) {
      $rel_candidates = array_intersect(
        ['canonical', 'edit-form'],
        array_flip($link_templates),
      );
      $rel = array_shift($rel_candidates);
      if ($rel === NULL) {
        throw new UndefinedLinkTemplateException("Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the '{$this->getEntityTypeId()}' entity type");
      }
    }

    // Links pointing to the current revision point to the actual entity. So
    // instead of using the 'revision' link, use the 'canonical' link.
    if ($rel === 'revision' && $this instanceof RevisionableInterface && $this->isDefaultRevision()) {
+4 −2
Original line number Diff line number Diff line
@@ -120,7 +120,9 @@ public function label();
   * entity/entityType/id.
   *
   * @param string $rel
   *   The link relationship type, for example: canonical or edit-form.
   *   The link relationship type, for example: canonical or edit-form. If none
   *   is provided, canonical is assumed, or edit-form if no canonical link
   *   exists.
   * @param array $options
   *   See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for
   *   the available options.
@@ -131,7 +133,7 @@ public function label();
   * @throws \Drupal\Core\Entity\EntityMalformedException
   * @throws \Drupal\Core\Entity\Exception\UndefinedLinkTemplateException
   */
  public function toUrl($rel = 'canonical', array $options = []);
  public function toUrl($rel = NULL, array $options = []);

  /**
   * Generates the HTML for a link to this entity.
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class EntityTestExternal extends EntityTest {
  /**
   * {@inheritdoc}
   */
  public function toUrl($rel = 'canonical', array $options = []) {
  public function toUrl($rel = NULL, array $options = []) {
    if ($rel === 'canonical') {
      return Url::fromUri('http://example.com', $options);
    }
+1 −1
Original line number Diff line number Diff line
@@ -1004,7 +1004,7 @@ public function save() {
  /**
   * {@inheritdoc}
   */
  public function toUrl($rel = 'edit-form', array $options = []) {
  public function toUrl($rel = NULL, array $options = []) {
    return $this->storage->toUrl($rel, $options);
  }

Loading