Link: write to this user in views

rajiv.r.in - August 12, 2009 - 13:11
Project:Privatemsg
Version:7.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:fixed
Description

I have a ‘view’ of users, showing selected users – as featured profiles’. I need to add a link to this view – against each user – for sending them a private message. How can I do it? Any help in this connection will be highly appreciated. Thx

#1

Berdir - August 12, 2009 - 13:32

There is no pre-built views integration right now, but you can easily use the function privatemsg_get_link() in a theme function.

1. Add a random field, for example the uid of the user. It does not matter as long as you can access the uid somehow.

2. Create a theme function for that field, and do something like this:

<?php
 
if ($url = privatemsg_get_link(array(user_load($insert_profile_uid_here)) {
    echo 
l(t('Send private message'), $url);
}
?>

That should display a link if the user is allowed to write a message.

Please set this to fixed if it does work.

#2

rajiv.r.in - August 12, 2009 - 13:41

This is little complicated for me. Can something be done using ‘Global: Custom text’ in views. But here I need a ‘replacement pattern’. Is that a possibility currently?

#3

rajiv.r.in - August 13, 2009 - 08:57

I also see a link on user page saying, "send this user a message". How do I use this feature from somewhere else? Can I link this from views?

#4

Berdir - August 14, 2009 - 16:09
Version:6.x-1.0-rc3» 6.x-1.x-dev
Category:support request» feature request
Priority:critical» normal
Status:active» needs review

Apply the (simple) patch and untar the tar.gz into the privatemsg folder. Clear the views cache and then you should have a configurable "Privatemsg: Send Privatemsg link"

AttachmentSize
privatemsg_views.tar_.gz 1.12 KB
privatemsg.views_api.patch 698 bytes

#5

Liliplanet - August 15, 2009 - 12:23

Hi Berdir,

This would be wonderful as an option in views.

Unfortunately, the patch seems to create the error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'privatemsg_user_access' was given in /home/public_html/includes/menu.inc on line 452..

This happens when visiting a profile page tpl with a custom send pm:

<?php
if (user_access('access private messages') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
   
$frommetoprofileuser = arg(1);
    if (
arg(0) == 'user' && is_numeric(arg(1))) {
            if (
$account->uid == $user->uid) {
                echo
'';
            }
            else {
            print
l(t('Send a Private Message ').$account->name, 'messages/new/'. $frommetoprofileuser);
         }
        }
    }
?>

Look forward to your reply, and thank you.
Lilian

#6

lasac - September 2, 2009 - 08:56

could the population field url be changed to the username instead of the uid..

#7

volocuga - September 27, 2009 - 21:45

Should it work (#4) if I have Content Profile installed?

Now I see only text "Send message:" without link.

#8

trupal218 - October 18, 2009 - 06:07

Hello,

Received the below error when saving the View with the new field to send private msg, and when visiting the page that has the view with the new field.

Fatal error: Call to undefined function privatemsg_user_access() in /home/example/public_html/drupal/sites/all/modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 60

Are others experiencing the same issue?
Thanks

#9

gsvitak - October 19, 2009 - 01:07

Hi

Thanks for the exciting patch.

I have a content type called idea and I have created a new view called similar ideas. I would like someone to search the view via filters and then allow someone to click an action link in the view to connect the current user to the author of the idea node. Is this possible with this patch or is this functionality supposed to work only on the profile node?

I am able to see the field type when I configure the view but I am not able to see see a link when I look at the view in the browser.How does the patch figure out which value to pass to the api? Do I need to do something special in the view configuration?

I know documentation is a pain for a patch but could someone please post a screen shot of a working configuration of the view and the field?

Thanks
Greg

#10

Berdir - October 19, 2009 - 21:04

@#8: Use the latest (rc4) version of privatemsg

@#9: Try the updated tar.gz (the patch did not change), that should work now. The reason was that the author field is actually called users_uid and not simply uid. This needs to be more flexible but for now, it should work for both cases. Note that you need to add the author as a field too, you can hide it if you don't want to display the author.

AttachmentSize
privatemsg_views2.tar_.gz 1.17 KB
privatemsg.views_api.patch 698 bytes

#11

gsvitak - October 19, 2009 - 22:05

#10

Thanks that works great..

Couple of other little things/feature requests?

How would I integrate into the Popups API (which is another great patch) ?

Also how would I prepopulate the message subject with the node title - just like the PrivateMsg with the PopupAPI/

Thanks again for the quick work?

Greg

#12

Berdir - October 20, 2009 - 00:23

Reworked the configuration completely.

It allows now to define the link text and the message subject and you can use tokens. You can also easily append the destination so that the user is redirected back to the form after sending the message by setting a checkbox.

@#11: The new subject configuration should solve your use case. Regarding popups module, check out the other issue, the last proposed version should work too for that too and there will hopefully be a new patch soon that will integrate that.

AttachmentSize
privatemsg_views3.tar_.gz 2.18 KB

#13

gsvitak - October 20, 2009 - 02:49

AWESOME!!!! Thank you for the quick turnaround

I tried the above tarball and the functionality works fine except I am getting the following error message when I run the view:

Missing argument 1 for views_handler_field::get_render_tokens(), called in /modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 125 and defined in modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 639

Text to display:
Send a Message to [name]

Pre-filled subject:
Reach Out request for Idea: [title]

Any suggestions?
G

#14

trupal218 - October 20, 2009 - 11:08

Thank you Berdir for this great addition to privatemsg!

As #13 gsvitak mentioned above I am also getting an error:

warning: Missing argument 1 for views_handler_field::get_render_tokens(), called in /home/example/public_html/drupal/sites/all/modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 125 and defined in /home/example/public_html/drupal/sites/all/modules/views/handlers/views_handler_field.inc on line 642.

#15

trupal218 - October 20, 2009 - 11:16

I added the field after the error msg above and clicked the send privatemsg link on the view.
It successfully went to the Send Message screen with the To: populated with the user from views (awesome!!)
I wrote a test msg 'testing privatemsg link with this message' and sent it - received below error message:
I hope my input helps debug any issues =)

* user warning: Unknown column 'format' in 'field list' query: INSERT INTO pm_message (subject, author, body, format, timestamp) VALUES ('testing privatemsg link with this message', 1, 'testing privatemsg link with this message', 1, 1256037087) in /home/example/public_html/drupal/sites/all/modules/privatemsg/privatemsg.module on line 1619.
* warning: Missing argument 1 for views_handler_field::get_render_tokens(), called in /home/example/public_html/drupal/sites/all/modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 125 and defined in /home/example/public_html/drupal/sites/all/modules/views/handlers/views_handler_field.inc on line 642.
* warning: Missing argument 1 for views_handler_field::get_render_tokens(), called in /home/example/public_html/drupal/sites/all/modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 125 and defined in /home/example/public_html/drupal/sites/all/modules/views/handlers/views_handler_field.inc on line 642.

#16

Berdir - October 20, 2009 - 11:20

I think you are using an old Views module. function get_render_tokens() in Views 2.6 does not have any arguments.

Edit: And for the second error, you need to run update.php.

#17

trupal218 - October 20, 2009 - 11:48

Ahh - sorry about the problem that was easily solved with update.php

I had this version installed:
Views 6.x-3.x-dev (2009-Oct-09)

Updated to this version:
Views 6.x-2.x-dev (2009-Oct-20)

still getting this error:
warning: Missing argument 1 for views_handler_field::get_render_tokens(), called in /home/example/public_html/drupal/sites/all/modules/privatemsg/views/views_handler_field_privatemsg_link.inc on line 125 and defined in /home/example/public_html/drupal/sites/all/modules/views/handlers/views_handler_field.inc on line 642.

does this only work for 6.x-2.6 official release?

#18

Berdir - October 20, 2009 - 16:23

The updated version should work with both 2.x-dev and 2.6.

AttachmentSize
privatemsg_views4.tar_.gz 2.18 KB

#19

gsvitak - October 20, 2009 - 22:42

Thanks again for the quick turn around..

I am using views dev-3.x.. I need to use this version due the multiple selection field groupings CCK field..

will try and let you know..

Thanks
Greg

#20

gsvitak - October 23, 2009 - 01:41

Hi

I tried the patch in #19 and it works great as long as you do not have popup-api patch applied as well. Somehow it appears the patch cause Jquery not be declared in the HTML output because firebug error console state "Jquery is undefined".

I will try and figure out the issue and post the fix.

Thanks again for the great work. Hopefully you can committ to the main dev branch for full release support.

#21

Berdir - October 23, 2009 - 18:45

Please provide a more detailed bug report in the other issue, with the exact error message (on which line, on which page and so on) including screenshots, if possible.

Also, try to check if that only happens when both patches are applied and not also if only the other patch is enabled. Thanks

#22

gsvitak - October 24, 2009 - 00:31

Appears the problem was with my view config. I had disabled the Use Ajax option to try and debug something. Everything works great.

Could you please add one more thing to the config? The label of the link always says Send Privatemsg link:

IE
Send Privatemsg link: Reach the author of this idea

Can you please change the config of the field label back to the first patch where I can enter what ever I wanted..

thanks
G

#23

Berdir - October 25, 2009 - 22:45

Re-added the Label configuration option and cleaned up option handling a bit, it should not work correctly with the default values.

AttachmentSize
privatemsg_views5.tar_.gz 2.21 KB

#24

gsvitak - October 26, 2009 - 19:48

Thanks will test tonight.

#25

gsvitak - October 27, 2009 - 04:40

works great.

I got the pop-ups to work by hardcoding the path of the page view into the module. It would be great if you could somehow add a config form to the patch to list out all possible paths that could be enabled.

function privatemsg_popups() {
if (variable_get('privatemsg_popups', TRUE)) {
return array(
'user/*' => array( // profile pages
'a[href*=messages/new]' // Send privatemsg
),
'node/*' => array( // node pages
'a[href*=messages/new]', // Send privatemsg
),
'similarideas/*' => array( // node pages
'a[href*=messages/new]', // Send privatemsg
),
'reachinview/*' => array( // node pages
'a[href*=messages/new]', // Send privatemsg
),
'*' => array(
'div#block-privatemsg-privatemsg-menu a[href*=messages/new]',
)
);
}
}

#26

andypost - October 30, 2009 - 06:53

I think using user_load() for every link is very expensive! Is this really required?

I found another views integration issue #502688: Views integration but it seems a wrong way

#27

Berdir - October 30, 2009 - 07:37

Yes, it is. The user object isn't required for views, it's required for privatemsg. Because all the permissions and blocking rules need to be checked and that needs a user object.

Edit: The other issue is about exposing the messages to views but that will not see the light any time soon. Simply because our queries are way to complex (With heavy use of Group By, Having, Subqueries and so on) for views.

#28

andypost - October 30, 2009 - 07:53

I think that better make own user_load() analog because this function is not cacheable so for every link the whole user+profile is loaded.

Upd: suppose new stdClass with uid is enough to check user_access() and query blocking rules...

#29

Berdir - October 30, 2009 - 09:25

I fully agree, that's something I want to do. But not only for views integration, privatemsg.module should use that function (privatemsg_user_load()) wherever possible, since we usually load *lots* of users and I'm really concerned about that.

So this isn't specific to this issue, please open a new task for this. You are also welcome to work on a patch. Note that the uid is not enough, we need atleast uid, name and the roles array.

#30

Berdir - November 9, 2009 - 16:45
Version:6.x-1.x-dev» 7.x-1.x-dev
Status:needs review» patch (to be ported)

Added to 6.x-1.x-dev. Needs to be ported to D7.

#31

Berdir - November 26, 2009 - 22:53

Commited to 7.x-1.x-dev.

#32

Berdir - November 27, 2009 - 07:25
Status:patch (to be ported)» fixed
 
 

Drupal is a registered trademark of Dries Buytaert.