44
55use Drupal \Component \EventDispatcher \Event ;
66use 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 }
0 commit comments