Hi,

I found a way to add 'Add to Friends' in a view with the following:

add [uid] as a field, then as a link:

flag/confirm/flag/friend/[uid]?destination=user/[uid]

The problem it shows even if a user is not logged in, so is there perhaps a way to give permissions to that specific field?

Naturally perhaps at a later stage, the 'flag friend links' will have the capability to also 'add to friend, instead of just 'remove friend'.

Basically I've created a view so that other users can see their friends, but would like to give them the option directly in the view to 'add to friends' without having to visit the user page.

Look forward to any reply, and thank you for this great module.

Lilian

Comments

vertazzar’s picture

the view will render the link regardless the permission, you must display the field by adding the field "Flag frined links" (Something like that) and you'll get the add/remove link with permissions.

i dont know if there's theme preprocess or hook code that allows you to set permission check on specific field.

liliplanet’s picture

Thank you vertazzar for your reply.

Unfortunately the 'flag friend links' are only for 'remove from your friends', 'pending' and 'approve' and not 'add to your friends'.

As per documentation: Flag friend only manipulates the provided flag (by Flag module) on the user profile page page for each user. This is what you use to "add a friend".

So just again please:

with: flag/confirm/flag/friend/[uid]?destination=user/[uid]

The problem the uid fields shows even if a user is not logged in, so is there perhaps a way to give permissions to that specific field?

Looking forward to any reply, and thank you :)
Lilian

vertazzar’s picture

the only thing i know about permissions views is that you can set entire view to require specific permission, or specific role , e.g.

authenticated user can view the view

but for specific field.. i dont know, i need more search, try first searching for a module that does that, than try for a php snippet.

sirkitree’s picture

If you look at the view provided (display flagged), you will see that it uses the field handler straight from Flag for this -- Flags: Flag link -- This handler checks to see if a user has permission to flag and displays accordingly.

sirkitree’s picture

Status: Active » Closed (fixed)

Also, using views in the way you describe above is not a good way to go about this. Closing issue due to lack of activity.

SyKce’s picture

I'm using a sidebar where information about the user being viewed is shown.
It contains also the relationship to this user with links to add or remove the relationship.

Here's how I've solved this with Views:

$view = new view;
$view->name = 'user_relationship';
$view->description = 'Provides a Block with user relationship operations';
$view->tag = 'flag.friend';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Standards', 'default');
$handler->override_option('relationships', array(
  'flag_content_rel' => array(
    'label' => 'flag',
    'required' => 0,
    'flag' => 'friend',
    'user_scope' => 'any',
    'id' => 'flag_content_rel',
    'table' => 'users',
    'field' => 'flag_content_rel',
    'override' => array(
      'button' => 'override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'uid' => array(
    'label' => 'Flag friend links',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 1,
    'id' => 'uid',
    'table' => 'flag_friend',
    'field' => 'uid',
    'relationship' => 'none',
  ),
  'ops' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_type' => '',
    'exclude' => 1,
    'id' => 'ops',
    'table' => 'flag_content',
    'field' => 'ops',
    'relationship' => 'flag_content_rel',
    'override' => array(
      'button' => 'override',
    ),
  ),
  'name' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '%1\'s [ops][uid]',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_user' => 0,
    'overwrite_anonymous' => 0,
    'anonymous_text' => '',
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'user',
    'default_argument' => '',
    'validate_type' => 'user',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '5' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'override' => array(
      'button' => 'override',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 1,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'blog' => 0,
      'panel' => 0,
      'profile' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'uid_current' => array(
    'operator' => '=',
    'value' => '0',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'uid_current',
    'table' => 'users',
    'field' => 'uid_current',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'role',
  'role' => array(
    '2' => 2,
  ),
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'User Relationship');
$handler->override_option('block_caching', -1);

After import, you have to 'rewrite the output' of the field user:name, so that it fits to your needs.
I use: %1's [ops][uid]
That produces an output like: 'become a friend of username' or 'cancel the friendship with username' (in my language)

I don't know if this is what was expected and is helpful for you but maybe for someone else.