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.

All other Modules /

Discuss all other Modules here.

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

Exposing Controller Actions as Menu Links


Go to End


2 Posts   995 Views

Avatar
plautzer

Community Member, 10 Posts

8 September 2016 at 6:30pm

Hi,

I would like to expose actions of a Customer Page to the Navigations as Sub menus.

E.g.
EventPage
-- AddEvent (Action of EventPage_Controller)
-- AddSeries (Action of EventPage_Controller)
-- ShowSeries (Action of EventPage_Controller)

I tried to build a submenu with VitualPages/Redirects but the URL_Segment is not allowed to be the Action of the Controller as this is check in Sitetree/Validate Function:

		if(self::config()->nested_urls && $parent = $this->Parent()) {
			if($controller = ModelAsController::controller_for($parent)) {
				if($controller instanceof Controller && $controller->hasAction($this->URLSegment)) return false;
			}
		} 

Is there away to disable that for a certain controller or hook in the Navigation and add the Links via Controller instead of CMS?

Thx in advance!

Avatar
plautzer

Community Member, 10 Posts

9 September 2016 at 6:11am

I found a solution by adding a customChildren to my page class which can be looped in the navigation template:

	public function customChildren(){
		
		if($this->member = Member::currentUser()) {
			$links = new ArrayList();
		
			$links->push(new ArrayData(array(
					'Link' => $this->Link() ."addevent",
					'Title' => "New Event"
					)));
		
			$links->push(new ArrayData(array(
					'Link' => $this->Link() . "series",
					'Title' => "New Series"
					)));
			return $links;
		}
		else 
			return FALSE;;

	}

Navigation.ss

             <% loop $Menu(1) %>
            <li class="$LinkingMode"><a href="$Link" title="$Title.XML">$MenuTitle.XML</a>  
                    <% if customChildren %>
                        <ul class="secondary">
                            <% loop customChildren %>
                                <li class=""><a href="$Me.Link">$Me.Title</a></li>
                            <% end_loop %>
                           <% if $Children %>
                                <% loop $Children %>
                                    <li class="<% if $isCurrent %>current<% else_if $isSection %>section<% end_if %>"><a href="$Link">$MenuTitle</a></li>
                                <% end_loop %>
                            <% end_if %>
                        </ul>
                <% else %>
                    <% if $Children %>
                        <ul class="secondary">
                            <% loop $Children %>
                                <li class="<% if $isCurrent %>current<% else_if $isSection %>section<% end_if %>"><a href="$Link">$MenuTitle</a></li>
                            <% end_loop %>
                        </ul>
                    <% end_if %>
                    
                 <% end_if %>
            </li>
            <% end_loop %>