Skip to content

Commit aa92d6b

Browse files
committed
Issue 843: Revalidate node path alias instead of node/#
1 parent c1a9054 commit aa92d6b

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

modules/next/src/Event/EntityActionEvent.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Component\EventDispatcher\Event;
66
use Drupal\Core\Entity\EntityInterface;
7+
use Drupal\Core\Url;
78

89
/**
910
* Defines an entity action event.
@@ -36,9 +37,9 @@ class EntityActionEvent extends Event implements EntityActionEventInterface {
3637
/**
3738
* The entity Url.
3839
*
39-
* @var string|null
40+
* @var \Drupal\Core\Url|null
4041
*/
41-
protected ?string $entityUrl;
42+
protected ?Url $entityUrl;
4243

4344
/**
4445
* EntityActionEvent constructor.
@@ -49,10 +50,10 @@ class EntityActionEvent extends Event implements EntityActionEventInterface {
4950
* The action.
5051
* @param array $sites
5152
* The sites for the entity.
52-
* @param string|null $entity_url
53+
* @param \Drupal\Core\Url|null $entity_url
5354
* The entity url.
5455
*/
55-
public function __construct(EntityInterface $entity, string $action, array $sites, ?string $entity_url) {
56+
public function __construct(EntityInterface $entity, string $action, array $sites, ?Url $entity_url) {
5657
$this->entity = $entity;
5758
$this->action = $action;
5859
$this->sites = $sites;
@@ -75,12 +76,7 @@ public static function createFromEntity(EntityInterface $entity, string $action)
7576
$next_entity_type_manager = \Drupal::service('next.entity_type.manager');
7677

7778
$sites = $next_entity_type_manager->getSitesForEntity($entity);
78-
try {
79-
$url = $entity->hasLinkTemplate('canonical') ? $entity->toUrl()->toString(TRUE)->getGeneratedUrl() : NULL;
80-
}
81-
catch (\Exception $e) {
82-
$url = NULL;
83-
}
79+
$url = $entity->hasLinkTemplate('canonical') ? $entity->toUrl() : NULL;
8480
return new static($entity, $action, $sites, $url);
8581
}
8682

@@ -132,14 +128,14 @@ public function setAction(string $action): EntityActionEventInterface {
132128
/**
133129
* {@inheritdoc}
134130
*/
135-
public function getEntityUrl(): ?string {
131+
public function getEntityUrl(): ?Url {
136132
return $this->entityUrl;
137133
}
138134

139135
/**
140136
* {@inheritdoc}
141137
*/
142-
public function setEntityUrl(string $url): EntityActionEventInterface {
138+
public function setEntityUrl(Url $url): EntityActionEventInterface {
143139
$this->entityUrl = $url;
144140
return $this;
145141
}

modules/next/src/Event/EntityActionEventInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\next\Event;
44

55
use Drupal\Core\Entity\EntityInterface;
6+
use Drupal\Core\Url;
67

78
/**
89
* Defines an interface for entity action events.
@@ -86,20 +87,20 @@ public function setAction(string $action): self;
8687
/**
8788
* Gets the url for the entity.
8889
*
89-
* @return string|null
90+
* @return \Drupal\Core\Url|null
9091
* The entity url.
9192
*/
92-
public function getEntityUrl(): ?string;
93+
public function getEntityUrl(): ?Url;
9394

9495
/**
9596
* Sets the url for the entity.
9697
*
97-
* @param string $url
98+
* @param \Drupal\Core\Url $url
9899
* The entity url.
99100
*
100101
* @return \Drupal\next\Event\EntityActionEventInterface
101102
* The event entity.
102103
*/
103-
public function setEntityUrl(string $url): self;
104+
public function setEntityUrl(Url $url): self;
104105

105106
}

modules/next/src/Plugin/Next/Revalidator/Path.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function revalidate(EntityActionEvent $event): bool {
7373

7474
$paths = [];
7575
if (!empty($this->configuration['revalidate_page'])) {
76-
$paths[] = $event->getEntityUrl();
76+
$paths[] = $event->getEntityUrl()->toString(TRUE)->getGeneratedUrl();
7777
}
7878
if (!empty($this->configuration['additional_paths'])) {
7979
$paths = array_merge($paths, array_map('trim', explode("\n", $this->configuration['additional_paths'])));

0 commit comments

Comments
 (0)