I'm using CAS Attributes in our D7 build to map names, addresses, job titles, etc, into Drupal. In LDAP, the street address ([cas:ldap:registeredaddress] token) is stored in this format, with a $ separating the street and city:
Streetname$City, State 00000-0000
With no way to get rid of that $
, I tried adding commas between the individual tokens like this:
[cas:ldap:street], [cas:ldap:l], [cas:ldap:st] [cas:ldap:postalcode]
This works, except some user accounts have empty LDAP tokens. When these users log in, the address field gets populated with:
, ,
What's the easiest way to transform the [cas:ldap:registeredaddress] token, or the address field and its individual tokens? I'm open to adding an override to a custom module if necessary. Thanks.
Comments
Comment #0.0
vinmassaro commentedclarity
Comment #1
olarin commentedSince this is sort of a special case of processing the formatting of data coming in from your CAS server, I think it probably does belong in a custom module as you suggested. As I see it, you have two major options - munge the data on the way in, or address the issue on display.
If you want to munge it on the way in, you can just use [cas:ldap:registeredaddress] and write a hook_tokens_alter to edit it.
If you don't want to muck with the token process, then depending on how you are going to use / display the data, you could just go ahead and store the street, city, state and zip separately or in a special field collection or something, and write some custom code to affect how they get displayed / used later - perhaps a field template in your theme for instance.
Comment #2
vinmassaro commentedThanks, I ended up using hook_tokens_alter to replace the $ with a comma:
Comment #2.0
vinmassaro commentedclarity