Drupal Rules reaction on CiviCRM Relationship create / update. It seems, that for Relationship Type only **[civicrm-relationship:relationship-type-id]** token is available, while we have both ID and Display Name for both contact A and B.
Any chance I can help to add Relationship Type "name" as token? I can make a patch, just not sure where to start from, searching module code has given some possible places to look, yet I am not sure about a correct path. Please advise. Thanks!

CommentFileSizeAuthor
#4 Capture.PNG37.83 KByurg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yurg created an issue. See original summary.

markusa’s picture

This could be a special case added to the civicrm_entity_entity_property_info_alter()
https://github.com/eileenmcnaughton/civicrm_entity/blob/7.x-2.x/civicrm_...

add an array for
$info['civicrm_relationship']['properties']['relationship_type_name']

and define your own custom setter and getter functions....

The "getter" function is what you really need to populate the value to be in Rules..It would be in that function that you lookup the the relationship type name from the id, via an API call.

Once you have a relationship_type_name property in the metadata, Rules should pick it up automatically.

markusa’s picture

You can also implement that same hook_entity_property_info_alter() hook in a custom module.

Another way to approach the problem you are having is to load the Relationship Type entity in Rules, from the id...and then you would have access to all the relationship type properties....in this way you wouldn't need any additional code

yurg’s picture

FileSize
37.83 KB

@markusa Thank you for input! I have tried to go "no coding" way first by loading Relationship Type in Rules via its ID, which unfortunately seems doesn't fully work.

"Fetch CiviCRM entity by property" loads all parts just fine and logical, it seems it tries to connect Relationship ID from Relationship with the same ID of Rel Type. It provides tokens for fetched entity like
**[entity-fetched-rel-type:0] CiviCRM Relationship Type with delta 0 The list item with delta 0. Delta values start from 0 and are incremented by one per list item.**

Yet after saving, it provides no data for tokens; it is also drops Relationship Type ID select on edit (you may want to have a look at grab below)

No relationship type loaded

Perhaps it is related to an error below:

Warning: Invalid argument supplied for foreach() in CivicrmEntityController->load() (line 71 of /civicrm_entity/civicrm_entity_controller.inc).

Perhaps having a "natural" (well, *natural* in terms of Drupal Rules) way of loading entities part via fetching by something would be preferable for advanced site builders. It is nice to have both though: token one could plug in and ability to fetch a whole entity.

It seems adding a token for Relationship Name is pretty straightforward (thanks a mil for pointing to the exact place in the code btw!!), going to play with it a bit too.

yurg’s picture

UPD: It seems an easier way has been found. Instead of using ** Fetch CiviCRM entity by property ** , another action with almost the same name has been used ( ** Fetch entity by id **) which is working as expected.

yurg’s picture

Assigned: Unassigned » yurg
Status: Active » Closed (works as designed)