Hi there,

just a question, if I have a site with a lot of users can I somehow build an Address book to manage my contacts and be able to quickly remember their user names. Is there already some module like this or would it be work from scratch?

thanks

Comments

ptmkenny’s picture

Version: » 7.x-2.x-dev
Category: feature » support
Status: Active » Closed (fixed)

I built something like this using Flag and Views. I allowed users to flag people they want to save to their contact lists. Then I made a view showing the flagged users and added Privatemsg links. Feel free to re-open if you need more details.

muschpusch’s picture

@ptmkenny: Would share your code as a feature?

ptmkenny’s picture

Greetings,

Sorry, I can't export the code easily as a feature, because some parts (the link to the contact list on the profile, which I display using Views and Panels) are unique to my site and it would include a lot of extraneous stuff.

But here's the flag code:

$flags = array();
// Exported flag: "Contact List".
$flags['contact_list'] = array(
  'content_type' => 'user',
  'title' => 'Contact List',
  'global' => 0,
  'types' => array(),
  'flag_short' => 'Add to contact list',
  'flag_long' => '',
  'flag_message' => '',
  'unflag_short' => 'Remove from contact list',
  'unflag_long' => '',
  'unflag_message' => '',
  'unflag_denied_text' => '',
  'link_type' => 'normal',
  'roles' => array(
    'flag' => array(
      0 => 2,
    ),
    'unflag' => array(
      0 => 2,
    ),
  ),
  'weight' => 0,
  'show_on_entity' => FALSE,
  'show_on_form' => 0,
  'access_author' => '',
  'show_on_profile' => 0,
  'access_uid' => 'others',
  'module' => '',
  'locked' => array(
    'name' => 'name',
  ),
  'api_version' => 2,
);
return $flags;

I can't export my view that shows the contact list because all the fields are specific to my site. However, this is basically just a view that shows the user profiles of users who have been flagged (formatted for the site) or a message that no one has been flagged yet by the user. I then added a link to this view to the privatemsg menu.

And here are a couple rules I added to give users visual confirmation that the flag actually did something:

{ "rules_show_confirmation_message_on_add_to_contact_list" : {
    "LABEL" : "Show confirmation message on add to contact list (en)",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "flag" ],
    "ON" : [ "flag_flagged_contact_list" ],
    "IF" : [
    ],
    "DO" : [
      { "drupal_message" : { "message" : "[flagged-user:name] has been added to your \u003Ca href=\u0022\/messages\/contact-list\u0022\u003Econtact list\u003C\/a\u003E." } }
    ]
  }
}

{ "rules_show_confirmation_message_on_remove_from_contact_list" : {
    "LABEL" : "Show confirmation message on remove from contact list (en)",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "flag" ],
    "ON" : [ "flag_unflagged_contact_list" ],
    "IF" : [
    ],
    "DO" : [
      { "drupal_message" : { "message" : "[flagged-user:name] has been removed from your \u003Ca href=\u0022\/messages\/contact-list\u0022\u003Econtact list\u003C\/a\u003E." } }
    ]
  }
}
muschpusch’s picture

Awesome. I will try to add some stuff to this and create a sandbox :)