Skip to content
Snippets Groups Projects
Verified Commit 627361ec authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3421114 by tstoeckler: [regression] Entity::toUrl() without argument is...

Issue #3421114 by tstoeckler: [regression] Entity::toUrl() without argument is broken for entity types with a URI callback

(cherry picked from commit c51465dd)
parent 41d193f7
No related branches found
No related tags found
9 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...
Pipeline #96439 passed
Pipeline: drupal

#96442

    ...@@ -164,6 +164,13 @@ public function toUrl($rel = NULL, array $options = []) { ...@@ -164,6 +164,13 @@ public function toUrl($rel = NULL, array $options = []) {
    // The links array might contain URI templates set in annotations. // The links array might contain URI templates set in annotations.
    $link_templates = $this->linkTemplates(); $link_templates = $this->linkTemplates();
    // 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()) {
    $rel = 'canonical';
    }
    $exception_message = "No link template '$rel' found for the '{$this->getEntityTypeId()}' entity type";
    // Use the canonical link template by default, or edit-form if there is not // Use the canonical link template by default, or edit-form if there is not
    // a canonical one. // a canonical one.
    if ($rel === NULL) { if ($rel === NULL) {
    ...@@ -174,16 +181,10 @@ public function toUrl($rel = NULL, array $options = []) { ...@@ -174,16 +181,10 @@ public function toUrl($rel = NULL, array $options = []) {
    $rel = 'edit-form'; $rel = 'edit-form';
    } }
    else { else {
    throw new UndefinedLinkTemplateException("Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the '{$this->getEntityTypeId()}' entity type"); $exception_message = "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()) {
    $rel = 'canonical';
    }
    if (isset($link_templates[$rel])) { if (isset($link_templates[$rel])) {
    $route_parameters = $this->urlRouteParameters($rel); $route_parameters = $this->urlRouteParameters($rel);
    $route_name = "entity.{$this->entityTypeId}." . str_replace(['-', 'drupal:'], ['_', ''], $rel); $route_name = "entity.{$this->entityTypeId}." . str_replace(['-', 'drupal:'], ['_', ''], $rel);
    ...@@ -207,7 +208,7 @@ public function toUrl($rel = NULL, array $options = []) { ...@@ -207,7 +208,7 @@ public function toUrl($rel = NULL, array $options = []) {
    $uri = call_user_func($uri_callback, $this); $uri = call_user_func($uri_callback, $this);
    } }
    else { else {
    throw new UndefinedLinkTemplateException("No link template '$rel' found for the '{$this->getEntityTypeId()}' entity type"); throw new UndefinedLinkTemplateException($exception_message);
    } }
    } }
    ......
    ...@@ -120,6 +120,7 @@ public function testToUrlNoId() { ...@@ -120,6 +120,7 @@ public function testToUrlNoId() {
    public function testToUrlDefaultException(): void { public function testToUrlDefaultException(): void {
    $values = ['id' => $this->entityId]; $values = ['id' => $this->entityId];
    $entity = $this->getEntity(UrlTestEntity::class, $values); $entity = $this->getEntity(UrlTestEntity::class, $values);
    $this->entityType->getUriCallback()->willReturn(NULL);
    $this->expectException(UndefinedLinkTemplateException::class); $this->expectException(UndefinedLinkTemplateException::class);
    $this->expectExceptionMessage("Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the '" . $this->entityTypeId . "' entity type"); $this->expectExceptionMessage("Cannot generate default URL because no link template 'canonical' or 'edit-form' was found for the '" . $this->entityTypeId . "' entity type");
    ...@@ -409,6 +410,9 @@ public function testToUrlUriCallback(array $bundle_info, $uri_callback) { ...@@ -409,6 +410,9 @@ public function testToUrlUriCallback(array $bundle_info, $uri_callback) {
    /** @var \Drupal\Core\Url $url */ /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl('canonical'); $url = $entity->toUrl('canonical');
    $this->assertUrl('<none>', [], $entity, TRUE, $url); $this->assertUrl('<none>', [], $entity, TRUE, $url);
    $url = $entity->toUrl();
    $this->assertUrl('<none>', [], $entity, TRUE, $url);
    } }
    /** /**
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment