CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal tokens
Pages: [1] 2

Author Topic: Drupal tokens  (Read 6116 times)

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Drupal tokens
April 19, 2011, 08:56:42 am
I have some tasks I'd like to accomplish, and I realize that exposing CiviCRM data as Drupal Tokens would be useful if not an obvious addition.
Since some of it is quite easy to implement, I am wondering if this has been done before or actually already available somewhere in CiviCRM.
I am running 3.3.6.

In the longer term, I plan on using Drupal Rules and doing conditional actions based on Contact attributes.
Ideally, I'd like to do that for Events as well.

I did see mention of a start on such a project a few years ago in this topic:
http://forum.civicrm.org/index.php/topic,8247.msg35645.html

I am willing to help start a project and can post code as I make progress.
Plus since this would be my first work that I'd contribute for CiviCRM, I'd like some feedback.

Thanks.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Drupal tokens
April 19, 2011, 10:08:40 am

this would be cool and help with further integration between drupal and civicrm, so go for it :)

might want to focus your energies on civicrm 4.0 / drupal 7 since thats the future (and present too!)

there is civicrm rules integration, specifically between civimail and rules. this is shipped as a drupal module in the standard civi distribution

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 19, 2011, 10:14:00 am
Thanks. I am going to continue moving forward on this.

Our enterprise only supports D6 now, but I'm willing to work with someone who is doing C4/D7 who can make sure that both will work.

Is this the right forum/topic to be posting this stuff to?
Also, where do I put my code once I have something to share?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Drupal tokens
April 19, 2011, 11:28:19 am

cool

ping us on irc if you need help/assistance. Might make things a lot easier to do so if u get stuck :)

i would create it as a drupal module and post the code to either github.com or create a sandbox on drupal.org

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Drupal tokens
April 19, 2011, 01:25:29 pm
Quote from: druderman on April 19, 2011, 10:14:00 am
Is this the right forum/topic to be posting this stuff to?
Also, where do I put my code once I have something to share?


I'd be interested in seeing what you come up with and helping if I can...
Lead Developer, C3 Design.
Twitter: @FatherShawn

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Drupal tokens
April 20, 2011, 02:45:39 am
Hey Father Shawn - I haven't seen you around for a bit - good to see you're still popping up.

I have been playing a bit with rules module & cck / fields - primarily in the context of other entities (because we want to create nodes / organic groups off event / group post hooks). Note that the fields / cck module currently in place does offer up a small number of tokens.

The integration we have allows an organic group to be created when an event is created (via rules) & for people to be added to it when they register for an event (depending on their role - rules condition).  When a teacher (role) is registered they become the group owner. Basically extending rules made this little 'chunk' a front end configuration rather than a bit of code.

I needed a way to link the node to the event so I decided to try to create a cck field for 'civicrm_entity' (where the entity type is a setting).  Currently stalled on the fact the api doesn't do LIKE '%%' across all entities - for the autocomplete fields - that's a post in the api forum at the moment & on learning a bit more & on the need to get other work done.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 20, 2011, 10:52:24 am
Excellent.

I'd like to make this Drupal module useful.

There are many Contact fields available, but some are just ids of foreign keys, so I have choosen the most useful fields for now.
I made the primary (or first) address and phone and email available, since there may be multiple of each.
I also really want to make Event tokens available, but I can see that may not be as simple as the Contact tokens.

My code so far works nicely, if you want to try it out.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Drupal tokens
April 20, 2011, 01:07:34 pm
Please post a link to your code so we can see it
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Drupal tokens
April 21, 2011, 03:58:55 am
Hi Eileen!

Yeah, I haven't been on the forums much lately - most of my time has been going into working with a really interesting congregation that worships in three different languages find common ground and common vision.  But now they're ready for a Drupal/Civi site as a communication hub so it's out of strategic discernment and back into geek mode!
Lead Developer, C3 Design.
Twitter: @FatherShawn

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 22, 2011, 07:36:43 am
I put up the source here.

https://github.com/druderman/civicrm_token

Please try it out and tell me what you think.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Drupal tokens
April 22, 2011, 10:42:26 am

hey druderman:

cool. thanx for the posting. A couple of comments and suggestions:

1. It would be a lot easier if:

token name == database column name

this will allow u to do "loops" on a fair part of your code in the module (specifically: civicrm_token_token_values)

2. If you do item 1 above, you can also get the titles automatically using some civicrm functions in the

civicrm_token_token_list

3. Not used the token module (and the hooks), but i'm curious as to how it "gets" the contact object which it sends to the token_values hook

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 22, 2011, 12:50:28 pm
I'll definitely look at 1. and 2. and see if that makes sense to rename the tokens.
Fortunately the coding standard forces you to provide tokens for descriptions of each field anyway.
Not knowing much about the database, I tried to use token names that match data member names in the DAO.
Since they are tokens and are going to be used by a Drupal configurator and not necessarily a programmer, so it makes sense that things are closer to straight-forward English, hence 'latitude' instead of 'geo_code_1'.

Regarding on how the $contact gets exposed to Drupal, basically any context in which tokens are used like Rules needs support to the publishing of the object.
The code to do so is in the civicrm_rules module which ships with civicrm. Mailing is also exposed.
Civicrm_rules uses civicrm hooks to trigger the Drupal Rules actions.
It is here or near here where I plan on adding the Events suport.

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 25, 2011, 10:33:27 am
I took Lobo's advice and rewrote the two Drupal Token functions to use the DAO fields. This shrunk the code down quite a bit and now nothing is hard-coded. The hardest part for me was convincing one of the functions to find the correct includes.

The token names have changed. I make available as tokens any Contact fields (and address, phone, and email) that were flagged for Export. There are a fewer Contact tokens and more Address and Email tokens now.

To test, enable the Drupal module Token and the civicrm_rules module in the CiviCRM distribution.
To see a list of tokens, go to yoursite.example.com/admin/help/token
To use, create a Rule condition or action in a Contact context.

https://github.com/druderman/civicrm_token

Please check it it out.

AKAKADAK

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.0
  • CMS version: Drupal 7.0
  • MySQL version: 5.5.9
  • PHP version: 5.3.5
Re: Drupal tokens
April 25, 2011, 11:31:24 am
@druderman: thanks for sharing.  Is there a central directory for CiviCRM modules?

druderman

  • I’m new here
  • *
  • Posts: 24
  • Karma: 0
  • CiviCRM version: 4.1+
  • CMS version: Drupal 7
  • MySQL version: 5.0.77 and 5.1
  • PHP version: 5.2.13
Re: Drupal tokens
April 25, 2011, 11:42:10 am
There just a few Drupal modules which come with CiviCRM, although I'm not exactly sure why.
There are more modules that are projects at drupal.org, which is where my Token module could live.

I'm posting here in order to get some feedback before I start a project.
Plus as noted above, it might make sense to support the new CiviCRM 3.4/4.0 release.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal tokens

This forum was archived on 2017-11-26.