-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add extension points to Link::getURL() #368
Comments
What's the use case for that extension hook? The only use cases I can think of would be better served as |
No worries :) My particular use case is adding an subject field to the EmailLink. The subject field is added via an extension. The url of the link should be something like I'm not keen on using onBeforeWrite because I want to keep the Email and EmailSubject fields separate. The other thing I can do in this case is create a custom EmailLink, or replace the original one via the injector. I thought that might be overkill since I'm just adding a single field. Keen to hear any alternative solutions as well :) Here's my extension code with the hook /**
* @extends Extension<(EmailLink & static)>
*
* @property ?string $EmailSubject
*/
class SubjectExtension extends Extension
{
private static array $db = [
'EmailSubject' => 'Varchar(255)',
];
protected function updateCMSFields(FieldList $fields): void
{
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'EmailSubject',
'Email subject'
)
);
}
protected function updateGetURL(string &$url): void
{
$emailSubject = $this->getOwner()->EmailSubject;
if ($emailSubject === null || $emailSubject === '') {
return;
}
$url = sprintf('%s?subject=%s', $url, $emailSubject);
}
} |
Makes sense, that's a very good use case for an extension hook. Thanks for being patient with me and explaining it so well |
PR merged. This will be included in the April minor release. |
Description
I'm migrating a project off
gorriecoe/silverstripe-link
. That module provides an extension point to update the url of the link which we use, it would be nice to have that functionality here as well. See the original extension point here.Additional context or points of discussion
No response
Validations
The text was updated successfully, but these errors were encountered: