Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Change menu_title of ModelAdmin


Go to End


3 Posts   1269 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

21 September 2010 at 1:52am

Hi,

I have a ModelAdmin where I need to change the name that appears in CMSMenu, but I cannot just change the...

static $menu_title = 'MyAdminOldName';

...I NEED to find a way of doing it outside of just changing the original static declaration.

I have tried and failed with...

inside a custom leftandmain decorator (does nothing)...

$menu_item = CMSMenu::get_menu_item('MyModelAdmin');//does return the right CMSMenuItem
CMSMenu::replace_menu_item('MyModelAdmin','NewName',$menu_item->url,$menu_item->controller,$menu_item->priority);

inside the init function of the extended ModelAdmin (does nothing)...

public function init()
{
	$this->set_stat('menu_title','NewName');
}

in _config.php (complains about trying to use a database object before the database has been initialised)...

MyModelAdmin::set_stat('menu_title','NewName');

Any ideas?

Avatar
martimiz

Forum Moderator, 1391 Posts

21 September 2010 at 7:43am


Adding a translation to your languagefile will do the trick. Suppose your ModelAdmin class is called MyModelAdmin:

In cms/lang/en_US.php add:

$lang['en_US']['MyModelAdmin']['MENUTITLE'] = 'Some Menutitle';

-Martine

Avatar
swaiba

Forum Moderator, 1899 Posts

21 September 2010 at 8:12pm

Now why didn't I think out that... Doh!

Many thanks Martimiz