TransWikia.com

How to get group id from custom url

Drupal Answers Asked by Leopathu on December 17, 2021

I have some more custom url with og group id like

  1. www.example.com/students/6593
  2. www.example.com/results/6953
  3. www.example.com/book-listing/5367/6953

    here 6953 is a group id.

these are the sample link. my questions is how to get the group id from url? And i can’t use arg(). because i have more no of url and group id position also varied.

There is any robust solutions for this.

One Answer

I have used the following code in hook_preprocess_page() to solve this issue.

$url = current_path();
  $arguments = explode('/', $url);
  foreach ($arguments as $value) {
    if (is_numeric($value)) {
      $node = node_load($value);
      if (og_is_group('node', $node)) {
        drupal_set_message('group id :' . $node->nid);
      }
    }
  }

From now, i can set to group member only could see this page.

Answered by Leopathu on December 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP