Howdy All,

Was wondering if there was a way to remove the "Twitter Accounts" DT from a user profile page.

It doesn't show up on the manage display page for user accounts and I would rather not hide it with CSS.

Any suggestions would be great.

Thanks - Jp

Comments

oliverwestbury’s picture

You can hide two codes via twitter module folder :- twitter.module

line 112:
/**
* Default callback for theme('twitter_user_accounts');
*
* Renders a list of Twitter accounts for the user profile page.
*/
// function theme_twitter_user_accounts($variables) {
// module_load_include('inc', 'twitter');
// $accounts = $variables['accounts'];
// $items = array();
// foreach ($accounts as $twitter_account) {
// $tweets = twitter_tweets($twitter_account->screen_name);
// // If we have tweets for this Twitter account, link to the View. If not, link to Twitter.
// if (count($tweets)) {
// $items[] = l('@' . $twitter_account->screen_name, 'tweets/' . $twitter_account->screen_name);
// }
// else {
// $items[] = _twitter_user_profile($twitter_account->screen_name);
// }
// }
// return theme('item_list', array('items' => $items));
// }

AND

line 350:
function twitter_user_view_alter(&$build) {
$user = $build['#account'];
// if (!empty($user->twitter_accounts)) {
// $build['twitter'] = array(
// '#type' => 'user_profile_item',
// '#title' => t('Twitter accounts'),
// '#markup' => theme('twitter_user_accounts', array('accounts' => $user->twitter_accounts)),
// '#weight' => 10,
// );
// }
}

ribakker’s picture

I think the solution by oliverwestbury is not recommended. That'd be a core hack to the original Twitter module code. It's better to implement hook_user_view_alter yourself and remove the Twitter item from there. Code example:

function your_module_name_user_view_alter(&$build) {
  if (array_key_exists('twitter', $build)) {
    unset($build['twitter']);
  }
}

You might also want to give your custom module a higher weight, otherwise the hook above will be fired too early. Code example:

function your_module_name_install() {
  db_update('system')->fields(array('weight' => 9999))->condition('name', 'your_module_name', '=')->execute();
}
mkolar’s picture

Issue summary: View changes

Solusion for version 7.x-5.8

/**
 * Remove twitter accounts from user view
 */
function yourmodule_user_view_alter(&$build) {
  
  if (isset($build["#account"]) 
      && is_object($build["#account"]) 
      && property_exists($build["#account"], "twitter_accounts")
  ) {
    unset($build["#account"]->twitter_accounts);
  }
}
doitDave’s picture

Subscribing for a better solution. Although I thank for the suggestions, I would prefer to have this information manageable in the "manage display" page, for of course I may want to display a user's twitter account, only I want to do it my way :)

Sorry I'm not so deep into Field API right now, otherwise I would have suggested a patch right away. Also, thanks for the all-in-all great module!

DamienMcKenna’s picture

Version: 7.x-6.0-alpha2 » 7.x-6.x-dev
madhaze’s picture

#3 worked for me but i would much rather be able to control it in manage display. Also This really needs any kind of wrapper with a class so it can be themed.

hawkeye.twolf’s picture

I agree that this belongs the module's configuration page. For the time being, I just did this, which to me is the best because I don't like messing with module weights:

/**
 * Implements hook_user_view_alter().
 *
 * Removes twitter accounts from user view. Two cases: the twitter module's hook
 * ran first, or our hook runs first.
 *
 * @see https://www.drupal.org/node/2082869
 */
function mymodule_user_view_alter(&$build) {
  // If twitter module's hook ran first.
  if (array_key_exists('twitter', $build)) {
    unset($build['twitter']);
  }
  // Otherwise, our module's hook ran first.
  elseif (isset($build["#account"]->twitter_accounts)) {
    unset($build["#account"]->twitter_accounts);
  }
}
DamienMcKenna’s picture

Title: Remove "Twitter Accounts" from user profile page » "Twitter accounts" should be managed via hook_field_extra_fields
Category: Support request » Feature request

Lets focus this on making the information manageable via hook_field_extra_fields.