-
Notifications
You must be signed in to change notification settings - Fork 202
Issue #1219 by rolki: Add the ability to get absolute URL of entity #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #1219 by rolki: Add the ability to get absolute URL of entity #1220
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of this change but lets make it slightly more generic so we don't end up adding individual attributes for all the possible options. If more dynamic options are needed based on user input then composition can be used to create the options array.
The change in the test shows that this allows the same behaviour but provides us more flexibility.
* "absolute" = @ContextDefinition("boolean", | ||
* label = @Translation("Make absolute"), | ||
* required = FALSE, | ||
* default_value = FALSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "absolute" = @ContextDefinition("boolean", | |
* label = @Translation("Make absolute"), | |
* required = FALSE, | |
* default_value = FALSE | |
* "absolute" = @ContextDefinition("array", | |
* label = @Translation("URL Options"), | |
* description = @Translation("Options to pass to the toUrl call"), | |
* required = FALSE, | |
* default_value = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "options" = @ContextDefinition("any",
* label = @Translation("URL Options"),
* description = @Translation("Options to pass to the toUrl call"),
* required = FALSE
Changed.
public function resolve(EntityInterface $entity, bool $absolute = NULL) { | ||
return $entity->toUrl('canonical', ['absolute' => $absolute ?? FALSE]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function resolve(EntityInterface $entity, bool $absolute = NULL) { | |
return $entity->toUrl('canonical', ['absolute' => $absolute ?? FALSE]); | |
public function resolve(EntityInterface $entity, array $options = []) { | |
return $entity->toUrl('canonical', $options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function resolve(EntityInterface $entity, ?array $options) {
return $entity->toUrl('canonical', $options ?? []);
Changed.
* The entity to get URL. | ||
* @param bool|null $absolute | ||
* Make the URL absolute. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The entity to get URL. | |
* @param bool|null $absolute | |
* Make the URL absolute. | |
* The entity to create a canonical URL for. | |
* @param array $options | |
* The options to provide to the URL generator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
|
||
$this->assertEquals($url, $this->executeDataProducer('entity_url', [ | ||
'entity' => $this->entity, | ||
'absolute' => TRUE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'absolute' => TRUE, | |
'options' => ['absolute' => TRUE], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…only one option
@Kingdutch |
Oh whelp. Too many things going on at once I suppose. Perhaps there was a good reason? I can’t find where we discussed it. 🤷♂️ |
I'm not sure we've discussed this, so this approach with options seems more flexible and logical. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, nice work and I think we can do this approach.
I have just one issue to change: we should expose the link relationship as well.
*/ | ||
public function resolve(EntityInterface $entity) { | ||
return $entity->toUrl(); | ||
public function resolve(EntityInterface $entity, ?array $options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in #1232 if changing the function signature of a dataproducer would be an API break in the stable version of the module.
But since this is such a simple dataproducer I think it is very unlikely that somebody extended this class, so I think we can do this.
public function resolve(EntityInterface $entity) { | ||
return $entity->toUrl(); | ||
public function resolve(EntityInterface $entity, ?array $options) { | ||
return $entity->toUrl('canonical', $options ?? []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it a good idea to hard code 'canonical'? I already see the next pull request coming wanting to have a parameter for the link relationship as well. I think we need to make that a parameter as well and default to 'canonical'.
Merged in #1291 . Thanks all! |
Fixes #1219