when a person does a action with ur like send a request, the relationship is not showing with the dev version, the custom message is %relationship_name, Your !relationship_name request has been sent to xxx

#8 dsm-placeholder-1485184.patch715 bytesmcrittenden
Members fund testing for the Drupal project. Drupal Association Learn more


aacraig’s picture

There is a bug in user_relationships_ui.module on line 29. It is missing the replacement value for the %relationship_name variable.

The correct code should be:

  foreach ($relationships as $relationship) {
    $msg = user_relationships_get_message('pending', $relationship, array(
      '!pending_relationship_requests'  => l(t('pending relationship requests'), variable_get('user_relationships_requests_link', 'relationships/requests')),
      '%relationship_name' => $relationship->name

    if (!in_array($msg, $notifications)) {
aacraig’s picture

After further testing, I see that the message parameter is missing in more than one message. That led me to discover the user_relationships_get_message() function in user_relationships.module, which I think is the true culprit.

On line 945, replace:

    $replaceables = user_relationships_type_translations(user_relationships_type_load($relationship->rtid)) + array(
      '!requester'                => theme('username', array('account' => $relationship->requester)),
      '!requestee'                => theme('username', array('account' => $relationship->requestee)),

with this:

    $replaceables = user_relationships_type_translations(user_relationships_type_load($relationship->rtid)) + array(
      '!requester'                => theme('username', array('account' => $relationship->requester)),
      '!requestee'                => theme('username', array('account' => $relationship->requestee)),
      '%relationship_name'  => $relationship->name

This always tries to replace the variable %relationship_name, regardless of which message it's in.

Berdir’s picture

user_relationships_type_translations() provides these placeholders already, see http://api.worldempire.ch/api/user_relationships/user_relationships.modu....

You need to use e.g. %rel_name instead of %relationship_name. Assuming that you customized the message and the default one is correct, this is merely a documentation issue, we need a change record for this.

aacraig’s picture

The error is in core user_relationships modules, not in custom code.

The message mentioned by printed by alejandro_oses is generated in the user_relationships_ui.module, for instance.

Berdir’s picture

Title: %relationship_name is not working » Replace remaining usages of old relationhip placeholders.

Not in 7.x-1.x-dev, not in that file...

There actually are some remaining usages of %relationship_name, but not in user_relationships_ui.module.

$ grep -R "%relationship_name" *
user_relationship_defaults/user_relationship_defaults.module:    '%relationship_name'  => user_relationships_type_get_name($relationship_type),
user_relationship_defaults/user_relationship_defaults.module:  drupal_set_message(t('Default relationship %relationship_name of %username has been added.', $message_p));
user_relationship_defaults/user_relationship_defaults.module:  watchdog('u_relationship', 'Default relationship %relationship_name of %username has been added.', $message_p, WATCHDOG_NOTICE, l(t('view'), 'admin/config/people/relationships'));
user_relationships.admin.inc:    '%relationship_name',
user_relationships_ui/user_relationships_ui.actions.inc:      '%relationship_name'        => $current_relationships[$rtid][0]->name,
user_relationships_ui/user_relationships_ui.install:  if (variable_get('user_relationships_msg_pending', FALSE) == t('!requester has requested to be your %relationship_name.  Please view your !pending_relationship_requests to approve them.', array())) {
user_relationships_ui/user_relationships_ui.install:    variable_set('user_relationships_msg_pending', t('!requester has requested to be your %relationship_name. View your !pending_relationship_requests to approve or decline.', array()));

- Those in user_relationhip_defaults.module should be updated to use the previously mentioned function but aren't technically broken because they are explicitly provides.
- The one in user_relationships.admin.inc is documentation and should be updated with those from the mentioned function instead. Probably move them out of the text there into a single list that also has descriptions.
- Same for the one in actions.inc, should be replaced with a call to the function.
- The one in .install is upgrade path and ok.

So, what's necessary here:
- Fix the the mentioned remaining uses of that one
- Document the new placeholders
- Create an upgrade path for custom messages
- Write a change record.

Patches are welcome :)

Triumphent’s picture

Great fix aacraig, thank you. It worked for me. More than a year after posting your fix in #2, the module still hasn't been corrected. And they claim it is "Actively maintained?" hmmmm....

Berdir’s picture

Well, it's marked as minimally maintained for now, happy? ;)

Still not seing a patch here.

mcrittenden’s picture

Status: Active » Needs review
715 bytes

Patch for #2.

Status: Needs review » Needs work

The last submitted patch, dsm-placeholder-1485184.patch, failed testing.

Berdir’s picture

The relationship doesn't have a name, only the type. And the correct fix is to change remaining cases that use %relationship_name to @rel_name.