How to get group container guid

Morning y'all,

I'm having a little problem getting group container_guid to get the specific group.

I'm viewing my events calendar from my profile page so i wanted to get the group it was created in but when i try

  • $group = elgg_get_page_owner_entity();
  •  
  • echo elgg_view('output/url', array(
                'text' => $group->name,
                'href' => $group->getURL(),
                'target' => '_blank',
    'container_guid' => $entity->guid,
            ));

it returns the current profile link instead.

Please how do i fix this. appreciate any help.

Thanks.

  • Mistake is:

    echo elgg_view('output/url', array(
            'text' => $group->name,
            'href' => $group->getURL(),
            'target' => '_blank',
            'container_guid' => $group->guid,
        ));

    Another way:

    $event_guid = (int) get_input('guid');
    $event = get_entity($event_guid);

    $group = elgg_get_page_owner_entity();

    $container = $event->getContainerEntity();
    if (elgg_instanceof($container, 'group')) {
            YOUR_CODE_HERE
    }

  • Thanks for your reply.

    Am sorry the code returned a blank page but when i remove this code
    $container = $event->getContainerEntity();

    The site will come up without any changes.

  • Make sure you have an event entity. Modify the code like this

    $event = get_entity($event_guid);
    if($event){
        $group = elgg_get_page_owner_entity();
        if (elgg_instanceof($group, 'group')) {
                YOUR_CODE_HERE
        }
    } else {
        echo "no event found";
    }    

  • Thanks for your contribution @Webgalli

    I tried the code, yes i have the event entity,
    but no changes took place. Still didn't display the group.

    I don't know what must be wrong.