Difference between revisions of "How to add user tab with Active Resources"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "Add this code to site.php file: <source> Am_Di::getInstance()->hook->add('userMenu', 'siteUserMenu'); function siteUserMenu(Am_Event $event) { $user = $event->getUse...")
 
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
Am_Di::getInstance()->hook->add('userMenu', 'siteUserMenu');
+
Am_Di::getInstance()->hook->add('userMenu', function (Am_Event $event) {
function siteUserMenu(Am_Event $event)
+
{
+
 
       $user = $event->getUser(); // if required
 
       $user = $event->getUser(); // if required
 
       $menu = $event->getMenu();
 
       $menu = $event->getMenu();
Line 30: Line 28:
 
           ));
 
           ));
 
       }
 
       }
}
+
});
 
//remove default Active Resources block
 
//remove default Active Resources block
 
Am_Di::getInstance()->blocks->remove('member-main-resources');
 
Am_Di::getInstance()->blocks->remove('member-main-resources');
 
</source>
 
</source>

Revision as of 04:53, 5 February 2016

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');