Problem/Motivation
When adding a non-authenticated Twitter account, either in the Twitter admin page (/admin/config/services/twitter) or in the user profile page itself (user/%uid/edit/twitter), the code just adds the uid of the logged in user to the twitter_accounts.uid column.
function twitter_non_auth_account_form_submit($form, &$form_state) {
$name = $form_state['values']['screen_name'];
$twitter = twitter_connect();
$twitter_account = $twitter->users_show($name, FALSE);
if (!isset($twitter_account->id)) {
form_set_error('screen_name', t('Could not add the Twitter account <em>@name</em>. ' .
'Check the recent messages log.', array('@name' => $name)));
}
else {
global $user;
$twitter_account->uid = $user->uid;
twitter_account_save($twitter_account, FALSE);
drupal_set_message(t('Twitter account added successfully'));
}
}
This causes a problem when you want to create a block of a user's tweets and display them on the user's profile page. Following the docs, you would clone the default Blocks display and add a contextual filter of the uid (the way the docs describe it is pretty inflexible in that it suggests adding a hardocded uid default value, when you can actually just use "User ID from URL"). The generated query joins the users table on the twitter_account table:
LEFT JOIN {users} users ON twitter_account.uid = users.uid
The problem is that since the form submit code just adds the logged in user id, if I'm an administrator adding Twitter account info for some users from their profile pages, my uid is written to twitter_user.uid, so even if I've run cron and there are records in the twitter table, any tweets from my account (if I have entered that one) will be returned for any account that I've entered Twitter accounts for at user/%uid/edit/twitter. In my case, once I manually edited the twitter_account.uid column, tweets started showing up just fine.
Proposed resolution
I see a patch that does the following three things solving the problem:
- In twitter_user_settings(), the $user object is available (as optional arg $account), since it has been passed to it from twitter_menu(), so pass it to twitter_non_auth_account_form:
if (twitter_connect()) { $output['add_account']['non_auth'] = drupal_get_form('twitter_non_auth_account_form', $account); }
- Add it as a hidden field in twitter_non_auth_account_form()
- Look for the uid in twitter_non_auth_account_form_submit(), and set $twitter_account->uid = $account->uid. Otherwise use the global value.
This will write the correct value to twitter_account.uid.
Remaining tasks
- Determine if suggestion is acceptable
- Write patch
Comment | File | Size | Author |
---|---|---|---|
#9 | twitter-n2212407-9-6.x-5.x.patch | 0 bytes | DamienMcKenna |
#5 | twitter-n2212407-5-7.x-6.x.patch | 1.6 KB | DamienMcKenna |
#4 | twitter-n2212407-4-7.x-5.x.patch | 1.58 KB | DamienMcKenna |
Comments
Comment #1
jonhines CreditAttribution: jonhines commentedI've implemented the close to the proposed suggestion and it appears to work fine for both the user specific and global non-auth account form.
Comment #2
jonhines CreditAttribution: jonhines commentedThis second patch is the same as the first but I accidentally deleted some code that differed between 5.8 and 5.x in the first one, it has been fixed here.
Comment #3
DamienMcKennaComment #4
DamienMcKennaI simplified it a little by passing the uid in as a hidden value on the non-auth form.
Comment #5
DamienMcKennaPorted to the 7.x-6.x branch.
Comment #7
DamienMcKennaForgot to change the branch when uploading the 7.x-6.x patch.
Comment #9
DamienMcKennaBackported to 6.x-5.x.
Comment #10
DamienMcKennaCommitted.