Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi
is there a solution that i can select more tokens for the product registration title in the registration information pane?
At the moment i can only choose [title] and [index] as token for the registration title.
Comments
Comment #1
Adam Wood CreditAttribution: Adam Wood commentedWe've had this requirement a few times, e.g. to add an product's date field data to the title for an event, and it's not that easy to override. Attached is a simple patch to add support for the Token module on the product registration title field, with the Commerce Order and Commerce Line Item objects available for each registration, whilst keeping the existing token functionality. You can get any product data you need from the Commerce Line Item.
It might be best to move all of the tokens for this into the Token module framework, and that would just require the module to define a custom token for the registration index. If a maintainer thinks this is a good idea, I'm happy to extend this patch. A decision would have to be made about what to do with the existing tokens.
Without using this patch, you need quite a messy form alter, as you have to re-use quite a bit of the original form to alter the elements. In case it's of interest to anyone, the following hook_form_FORM_ID_alter() will allow you to override the title without this patch (only tested on 7.x-2.x-dev):
Comment #2
blacklabel_tom CreditAttribution: blacklabel_tom commentedHi Adam,
Thanks for your work on this issue, if you are happy to knock the module into shape with the token framework I would welcome any patches.
I think that would be the best way to fulfil this requirement.
Cheers
Tom
Comment #3
Adam Wood CreditAttribution: Adam Wood commentedHi Tom,
I didn't notice that you were a maintainer. Small (Drupal) world...
Updated patch attached that provides support for tokens on the title and help text fields, and a custom token type for the module and token for the 'index'. It keeps support for the [title] and [index] tokens, but references to them have been removed on the form. Their tokens are now:
[title] -> [commerce-line-item:commerce-product:title]
[index] -> [commerce-registration:registration-index]
I'm not sure about some of the terminology used, mainly 'The numerical index of the registration for a product.', but take a look and see what you think.
Cheers
Adam
Comment #4
blacklabel_tom CreditAttribution: blacklabel_tom commentedHi Adam,
It certainly is a small world!
Patch looks good to me, leaving as needs review for someone to OK this.
Give me a nudge if there is no movement on this in a couple of weeks and I'll push it into the dev branch. Hopefully someone will come along and review this in the meantime, but no problem if not.
Cheers
Tom
Comment #5
Adam Wood CreditAttribution: Adam Wood commentedThanks Tom, will do.
There were a few inconsistencies in the hook_tokens() and a typo in the checkout_pane.inc that I've updated in the attached patch.
Comment #6
mabo1972 CreditAttribution: mabo1972 commentedComment #8
blacklabel_tom CreditAttribution: blacklabel_tom commentedComment #9
blacklabel_tom CreditAttribution: blacklabel_tom commentedSorry mabo1972, forgot to give you credit in the commit!