Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions modules/next/src/Event/EntityActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Component\EventDispatcher\Event;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
* Defines an entity action event.
Expand Down Expand Up @@ -36,9 +37,9 @@ class EntityActionEvent extends Event implements EntityActionEventInterface {
/**
* The entity Url.
*
* @var string|null
* @var \Drupal\Core\Url|null
*/
protected ?string $entityUrl;
protected ?Url $entityUrl;

/**
* EntityActionEvent constructor.
Expand All @@ -49,10 +50,10 @@ class EntityActionEvent extends Event implements EntityActionEventInterface {
* The action.
* @param array $sites
* The sites for the entity.
* @param string|null $entity_url
* @param \Drupal\Core\Url|null $entity_url
* The entity url.
*/
public function __construct(EntityInterface $entity, string $action, array $sites, ?string $entity_url) {
public function __construct(EntityInterface $entity, string $action, array $sites, ?Url $entity_url) {
$this->entity = $entity;
$this->action = $action;
$this->sites = $sites;
Expand All @@ -75,12 +76,7 @@ public static function createFromEntity(EntityInterface $entity, string $action)
$next_entity_type_manager = \Drupal::service('next.entity_type.manager');

$sites = $next_entity_type_manager->getSitesForEntity($entity);
try {
$url = $entity->hasLinkTemplate('canonical') ? $entity->toUrl()->toString(TRUE)->getGeneratedUrl() : NULL;
}
catch (\Exception $e) {
$url = NULL;
}
$url = $entity->hasLinkTemplate('canonical') ? $entity->toUrl() : NULL;
return new static($entity, $action, $sites, $url);
}

Expand Down Expand Up @@ -132,14 +128,14 @@ public function setAction(string $action): EntityActionEventInterface {
/**
* {@inheritdoc}
*/
public function getEntityUrl(): ?string {
public function getEntityUrl(): ?Url {
return $this->entityUrl;
}

/**
* {@inheritdoc}
*/
public function setEntityUrl(string $url): EntityActionEventInterface {
public function setEntityUrl(Url $url): EntityActionEventInterface {
$this->entityUrl = $url;
return $this;
}
Expand Down
9 changes: 5 additions & 4 deletions modules/next/src/Event/EntityActionEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\next\Event;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
* Defines an interface for entity action events.
Expand Down Expand Up @@ -86,20 +87,20 @@ public function setAction(string $action): self;
/**
* Gets the url for the entity.
*
* @return string|null
* @return \Drupal\Core\Url|null
* The entity url.
*/
public function getEntityUrl(): ?string;
public function getEntityUrl(): ?Url;

/**
* Sets the url for the entity.
*
* @param string $url
* @param \Drupal\Core\Url $url
* The entity url.
*
* @return \Drupal\next\Event\EntityActionEventInterface
* The event entity.
*/
public function setEntityUrl(string $url): self;
public function setEntityUrl(Url $url): self;

}
2 changes: 1 addition & 1 deletion modules/next/src/Plugin/Next/Revalidator/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function revalidate(EntityActionEvent $event): bool {

$paths = [];
if (!empty($this->configuration['revalidate_page'])) {
$paths[] = $event->getEntityUrl();
$paths[] = $event->getEntityUrl()->toString(TRUE)->getGeneratedUrl();
}
if (!empty($this->configuration['additional_paths'])) {
$paths = array_merge($paths, array_map('trim', explode("\n", $this->configuration['additional_paths'])));
Expand Down