Pages

Sunday, May 5, 2013

Social Engine 4 - Adding a Menu Item to a Menu Specified under Module(create a menu plugin)

First things first

1. Create/Add a menu item to respective menu from admin

Layout=>Menu Editor

2. Now in table "engine4_core_menuitems" set the following attributes

name="credit_main_network" //we will use this later in code avoid spaces
module=Credit(your module name)
label=Network(label of your menu item)
plugin=Credit_Plugin_Menus
{"route" : "credit_general","action":network}


3. Next route will be defined in your "modulename/settings/manifest.php"

for example

'credit_general'=>array(
'route'=>'credits/:action/*',
'defaults'=>array(
      'module'=>'credit',
      'controller'=>'index',
      'action'=>'index'
      ),
'menu'=>'credit_main' //(from table engine4_core_menus)
'submenu'=> if any
'enabled'=>1,
'order'=>3
)

4. Now in plugin under your module create a file "Menus.php"(if not there)

and template it as follows

for example for me file was /module/credit/Plugin/menus.php

class Credit_Plugin_Menus
{
     // see name of menu from table we have used after underscore

    public function onMenuInitialize_CreditMainNetwork($row)
   {
           If(!Engine_Api::_()->user()->getViewers()->getIdentity())
           {
               return false;
           }
           return true;
   }
}

That's it you have successfully configured menu for your Module in Social Engine 4

1 comment:

  1. In the class we can also return an array of menu parameters as

    public function onMenuInitialize_AlbumIndexBrowse($row)
    {
    $viewer=Engine_API::_()->user()->getView();
    if($viewer->getIdentity())
    {
    return array(
    // label which you pass from backend
    'label'=>$row->label;
    'icon'=>'album_general';
    'params'=>
    array(
    'id'=>$viewer->getIdentity();
    )
    )
    }
    return false;
    }

    you can check from user module file Menus.php located in

    User/Plugin/Menus.php

    ReplyDelete