Skip to main content
added 436 characters in body
Source Link

Im using drupal 7 and group module

I am trying to run some code only if the current page is a group.

here is my code

<?php
$arg = arg(0);
$arg1 = arg(1);
global $user;
if($arg ='group' && is_numeric($arg1)) {
    $group = group_load($arg1);
    if($group->getMember($user->uid)) { 
       print ('user is member');  
    };
};
?>

If this is placed on a group page it will print user is member if the current user is a member. If the current user isn't a member it will not show anything. Which is what it is supposed to do.

If I navigate to a none group page I get an error 'Error: Call to a member function getMember()', but the if statement should prevent this?

How do I check if the current page is a group entity?

Thanks

Edit

I wanted to return true if a group page and user is a member of the group. Using menu_get_object by Jaypan I used the code below to show. Im checking if page is group if so loading the group then checking if the user is a member of the group.

if (!empty(menu_get_object('group')))
   { 
   $group = group_load(arg(1));
   if($group->getMember($user->uid)) { 
       return TRUE;  
    }
}

Im using drupal 7 and group module

I am trying to run some code only if the current page is a group.

here is my code

<?php
$arg = arg(0);
$arg1 = arg(1);
global $user;
if($arg ='group' && is_numeric($arg1)) {
    $group = group_load($arg1);
    if($group->getMember($user->uid)) { 
       print ('user is member');  
    };
};
?>

If this is placed on a group page it will print user is member if the current user is a member. If the current user isn't a member it will not show anything. Which is what it is supposed to do.

If I navigate to a none group page I get an error 'Error: Call to a member function getMember()', but the if statement should prevent this?

How do I check if the current page is a group entity?

Thanks

Im using drupal 7 and group module

I am trying to run some code only if the current page is a group.

here is my code

<?php
$arg = arg(0);
$arg1 = arg(1);
global $user;
if($arg ='group' && is_numeric($arg1)) {
    $group = group_load($arg1);
    if($group->getMember($user->uid)) { 
       print ('user is member');  
    };
};
?>

If this is placed on a group page it will print user is member if the current user is a member. If the current user isn't a member it will not show anything. Which is what it is supposed to do.

If I navigate to a none group page I get an error 'Error: Call to a member function getMember()', but the if statement should prevent this?

How do I check if the current page is a group entity?

Thanks

Edit

I wanted to return true if a group page and user is a member of the group. Using menu_get_object by Jaypan I used the code below to show. Im checking if page is group if so loading the group then checking if the user is a member of the group.

if (!empty(menu_get_object('group')))
   { 
   $group = group_load(arg(1));
   if($group->getMember($user->uid)) { 
       return TRUE;  
    }
}
Source Link

How to check if current page is a group entity?

Im using drupal 7 and group module

I am trying to run some code only if the current page is a group.

here is my code

<?php
$arg = arg(0);
$arg1 = arg(1);
global $user;
if($arg ='group' && is_numeric($arg1)) {
    $group = group_load($arg1);
    if($group->getMember($user->uid)) { 
       print ('user is member');  
    };
};
?>

If this is placed on a group page it will print user is member if the current user is a member. If the current user isn't a member it will not show anything. Which is what it is supposed to do.

If I navigate to a none group page I get an error 'Error: Call to a member function getMember()', but the if statement should prevent this?

How do I check if the current page is a group entity?

Thanks