I have a Quicktab with 2 tabs. The block is placed in user profile.
Now I want to show one of the blocks only when the user visits his own profile and hide it when he is visiting other profiles. How may I do this?
In Drupal 7 you can use hook_quicktabs_alter
/**
* Implementing hook_quicktabs_alter
* @param type $quicktabs
*/
function MODULE_NAME_quicktabs_alter(&$quicktabs) {
global $user;
foreach ($quicktabs->tabs as $key => $tab) {
if ($tab['title'] == 'Tab1' && arg(0) == 'user' && is_numeric(arg(1)) && $user->uid == arg(1)) {//check condition as per your requirement
unset($quicktabs->tabs[$key]);
}
}
}
you would need to put that code right where you want the quicktab to render:
<?php
// Current user uid.
global $user;
$userUid = $user->uid;
// Uid of the user's viewed profile.
$userUidViewedProfile = $arg(1)
// Condition if current userId = userId's viewed profile. If it is, render the quicktab.
if ($userUid == $userUidViewedProfile)
{
$block = module_invoke('quicktabs', 'block_view', 'machine_name'); // Only change the machine name here,
print render($block);
}
?>