How to add user tab with Active Resources

From aMember Pro Documentation
Revision as of 04:53, 5 February 2016 by Caesar (Talk | contribs)

Jump to: navigation, search

Add this code to site.php file:

Am_Di::getInstance()->hook->add('userMenu',  function (Am_Event $event) {
      $user = $event->getUser(); // if required
      $menu = $event->getMenu();
 
      $items = array();
      foreach(Am_Di::getInstance()->resourceAccessTable->getAllowedResources($user,
            ResourceAccess::USER_VISIBLE_TYPES) as $r) {
 
          $url = $r->getUrl();
          $title = $r->getLinkTitle();
          if (!$url || !$title || $r->hide) continue;
          $items[] = array(
              'id' => 'resource-' . $r->pk(),
              'uri' => $url,
              'label' => $title
          );
      }
 
      if ($items) { //if we have at least one available resource
          $menu->addPage(array(
                  'id' => 'site-resources',
                  'label' => ___('Active Resources'),
                  'uri' => '#',
                  'order' => 300,
                  'pages' => $items
          ));
      }
});
//remove default Active Resources block
Am_Di::getInstance()->blocks->remove('member-main-resources');