MW Customer Area Menu rename items

Jamie Whittingham

Active Member
Hi @twisted1919

So im using the following code to build my own menu for the customers area

PHP:
public function run(){
        // hook into the menu geberation filter
        Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', function($menuItems){
            // unset the given menu item
                   
           $customer   = Yii::app()->customer->getModel();

           $menuItems = array(
               'dashboard' => array(
                   'name'      => Yii::t('app', 'Dashboard'),
                   'icon'      => 'glyphicon-dashboard',
                   'active'    => 'dashboard',
                   'route'     => array('dashboard/index'),
               ),
               /*
               'price_plans' => array(
                   'name'      => Yii::t('app', 'Price plans'),
                   'icon'      => 'glyphicon-credit-card',
                   'active'    => 'price_plans',
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('price_plans/index'), 'label' => Yii::t('app', 'Price plans'), 'active' => strpos($route, 'price_plans/index') === 0 || strpos($route, 'price_plans/payment') === 0),
                       array('url' => array('price_plans/orders'), 'label' => Yii::t('app', 'Orders history'), 'active' => strpos($route, 'price_plans/order') === 0),
                   ),
               ),
               */
               'lists' => array(
                   'name'      => Yii::t('app', 'Mailing Lists'),
                   'icon'      => 'glyphicon-list-alt',
                   'active'    => array('lists', 'email'),
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('lists/index'), 'label' => Yii::t('app', 'Mailing Lists'), 'active' => strpos($route, 'lists') === 0 && strpos($route, 'lists_tools') === false),
                       array('url' => array('lists_tools/index'), 'label' => Yii::t('app', 'Sync / Split Lists'), 'active' => strpos($route, 'lists_tools') === 0),
                       array('url' => array('email-blacklist/index'), 'label' => Yii::t('app', 'Email Blacklist'), 'active' => strpos($route, 'lists_tools') === 0),
                   ),
               ),
               /*
               'suppression' => array(
                   'name'      => Yii::t('app', 'Email Suppression'),
                   'icon'      => 'glyphicon-remove',
                   'active'    => 'email-blacklist',
                   'route'     => array('email-blacklist/index'),
               ),
               */
               'campaigns' => array(
                   'name'      => Yii::t('app', 'Mailing Campaigns'),
                   'icon'      => 'glyphicon-envelope',
                   'active'    => 'campaign',
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('campaigns/index'), 'label' => Yii::t('app', 'Mailing Campaigns'), 'active' => strpos($route, 'campaigns') === 0),
                       array('url' => array('campaign_groups/index'), 'label' => Yii::t('app', 'Groups'), 'active' => strpos($route, 'campaign_groups') === 0),
                       array('url' => array('campaign_tags/index'), 'label' => Yii::t('app', 'Custom Tags'), 'active' => strpos($route, 'campaign_tags') === 0),
                   ),
               ),
               'templates' => array(
                   'name'      => Yii::t('app', 'Email Templates'),
                   'icon'      => 'glyphicon-text-width',
                   'active'    => 'templates',
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('templates/index'), 'label' => Yii::t('app', 'My Templates'), 'active' => in_array($route, array('templates/index', 'templates/create', 'templates/update'))),
                       array('url' => array('templates/gallery'), 'label' => Yii::t('app', 'Template Gallery'), 'active' => strpos($route, 'templates/gallery') === 0),
                   ),
               ),
               'servers'       => array(
                   'name'      => Yii::t('app', 'My Servers'),
                   'icon'      => 'glyphicon-transfer',
                   'active'    => array('delivery_servers', 'bounce_servers', 'feedback_loop_servers'),
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('delivery_servers/index'), 'label' => Yii::t('app', 'Delivery Servers'), 'active' => strpos($route, 'delivery_servers') === 0),
                       array('url' => array('bounce_servers/index'), 'label' => Yii::t('app', 'Bounce Servers'), 'active' => strpos($route, 'bounce_servers') === 0),
                       array('url' => array('feedback_loop_servers/index'), 'label' => Yii::t('app', 'Feedback Loop Servers'), 'active' => strpos($route, 'feedback_loop_servers') === 0),
                   ),
               ),
               'domains' => array(
                   'name'      => Yii::t('app', 'My Domains'),
                   'icon'      => 'glyphicon-globe',
                   'active'    => array('sending_domains', 'tracking_domains'),
                   'route'     => null,
                   'items'     => array(
                       array('url' => array('sending_domains/index'), 'label' => Yii::t('app', 'Sending Domains'), 'active' => strpos($route, 'sending_domains') === 0),
                       array('url' => array('tracking_domains/index'), 'label' => Yii::t('app', 'Tracking Domains'), 'active' => strpos($route, 'tracking_domains') === 0),
                   ),
               ),
               'api-keys' => array(
                   'name'      => Yii::t('app', 'API Keys'),
                   'icon'      => 'glyphicon-star',
                   'active'    => 'api_keys',
                   'route'     => array('api_keys/index'),
               ),
               /*
               'articles' => array(
                   'name'      => Yii::t('app', 'Articles'),
                   'icon'      => 'glyphicon-book',
                   'active'    => 'article',
                   'route'     => Yii::app()->apps->getAppUrl('frontend', 'articles', true),
                   'items'     => array(),
               ),
               */
               'settings' => array(
                   'name'      => Yii::t('app', 'Settings'),
                   'icon'      => 'glyphicon-cog',
                   'active'    => 'settings',
                   'route'     => null,
                   'items'     => array(),
               ),
           );
   
           $maxDeliveryServers = $customer->getGroupOption('servers.max_delivery_servers', 0);
           $maxBounceServers   = $customer->getGroupOption('servers.max_bounce_servers', 0);
           $maxFblServers      = $customer->getGroupOption('servers.max_fbl_servers', 0);
           
           if (!$maxDeliveryServers && !$maxBounceServers && !$maxFblServers) {
               unset($menuItems['servers']);
           } else {
               foreach (array($maxDeliveryServers, $maxBounceServers, $maxFblServers) as $index => $value) {
                   if (!$value && isset($menuItems['servers']['items'][$index])) {
                       unset($menuItems['servers']['items'][$index]);
                   }
               }
           }
           
           if (SendingDomain::model()->getRequirementsErrors() || $customer->getGroupOption('sending_domains.can_manage_sending_domains', 'no') != 'yes') {
               unset($menuItems['domains']['items'][0]);
           }
   
           if ($customer->getGroupOption('tracking_domains.can_manage_tracking_domains', 'no') != 'yes') {
               unset($menuItems['domains']['items'][1]);
           }
   
           if ($customer->getGroupOption('lists.can_use_own_blacklist', 'no') != 'yes') {
               unset($menuItems['lists']['items'][2]);
           }
           
           return $menuItems;
        });
    }


What I would like to try and do though is not rewrite the entire menu myself but find and replace certain menu items that you have in the stock version.

How would I go about the following

find the menu item named 'Domains' and rename is without having to build the entire men item from scratch after unsetting your menu.

hope this makes sense

thanks
 
The $menuItem variable that is passed in:
PHP:
Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', function($menuItems){
is an associative array, where the keys are the item ids you can use to identify, to be more clear:
PHP:
$menuItems['domains']['name'] = 'Whatever else';
will rename the domains menu item.

so:
PHP:
Yii::app()->hooks->addFilter('customer_left_navigation_menu_items', function($menuItems){
    $menuItems['domains']['name'] = 'Whatever else';
    return $menuItems;
});

This is just plain PHP stuff...
 
Back
Top