Message-ID: <1533510582.3168.1485852259505.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3167_699259508.1485852259505" ------=_Part_3167_699259508.1485852259505 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Configure the navigation

Configure the navigation

=20 =20

PlatformUI Naviga= tion Hub

As written in the Platfor= mUI technical introduction, the Navigation Hub gives access to 4 naviga= tion zones which have a set of navigation items. Each Navigation Item is ac= tually a View in the Navigation Hub which can generate one or more links in= the menu. Most Navigation Items can even be seen as a View of a given appl= ication route. A Navigation Item View is also responsible for handling its = selected state. This means that the Navigation Items are notified = when the application matches a new route and the view can then decide to re= act accordingly.

PlatformUI comes with 3 different implementations of Navigation Item. Th= ey all generate a link to a route with a given anchor text and they differ = by the ability to check if the newly matched route in the application is th= e route they represent:

The default structure of the Navigation Hub is defined in the Navigation Hub view service attributes.

Adding a new nav= igation item

Plug= in for the Navigation Hub view service

Since the menu structure is defined in the Navigation Hub view service, = we need to write a plugin for the Navigation Hub view service. Again, we'll= create a module that will define a plugin. So the first thing to do is to = declare our new module in yui.yml:

yui.yml
=20
ezconf-navigationplugin:
    requires: ['ez-pluginregistry', 'ez-viewservicebaseplugin'] # ez-viewse=
rvicebaseplugin instead of plugin, base for plugins for view services
    dependencyOf: ['ez-navigationhubviewservice']
    path: %extending_platformui.public_dir%/js/views/services/plugins/ezcon=
f-navigationplugin.js
=20

View service plugins are a bit special, they need to follow a specific i= nterface provided by Y.eZ.Plu= gin.ViewServiceBase whic= h is defined in the ez-viewservicebaseplugin module, so our mo= dule needs to require it.

Then, the base plugin can be written on disk. It is very close to the ba= se plugin written in the Alter the JavaScript Application routing step:

ezconf-navigationplugin.js
=20
YUI.add('ezconf-navigationplugin', function (Y) {
    Y.namespace('eZConf.Plugin');

    // view service plugins must extend Y.eZ.Plugin.ViewServiceBase
    // Y.eZ.Plugin.ViewServiceBase provides several method allowing to deep=
ly
    // hook into the view service behaviour
    Y.eZConf.Plugin.NavigationPlugin =3D Y.Base.create('ezconfNavigationPlu=
gin', Y.eZ.Plugin.ViewServiceBase, [], {
        initializer: function () {
            var service =3D this.get('host'); // the plugged object is call=
ed host

            console.log("Hey, I'm a plugin for NavigationHubViewService");
            console.log("And I'm plugged in ", service);
        },
    }, {
        NS: 'ezconfNavigation'
    });

    Y.eZ.PluginRegistry.registerPlugin(
        Y.eZConf.Plugin.NavigationPlugin, ['navigationHubViewService']
    );
});
=20

At this point, if you refresh you browser, the navigation hub should rem= ain the same but you should see new messages in the console.

Adding a new n= avigation item

Now that we have plugin plugged in the Navigation Hub View service, we c= an change the menu structure. Among others methods, the Navigation Hub view= service has an addNavigationItem method to= add a navigation item in a given zone, so we can use it in our plugin to a= dd a new item:

ezconf-navigationplugin.js
=20
YUI.add('ezconf-navigationplugin', function (Y) {
    Y.namespace('eZConf.Plugin');

    Y.eZConf.Plugin.NavigationPlugin =3D Y.Base.create('ezconfNavigationPlu=
gin', Y.eZ.Plugin.ViewServiceBase, [], {
        initializer: function () {
            var service =3D this.get('host');

            console.log("Hey, I'm a plugin for NavigationHubViewService");
            console.log("And I'm plugged in ", service);

            console.log("Let's add the navigation item in the Content zone"=
);
            service.addNavigationItem({
                Constructor: Y.eZ.NavigationItemView,
                config: {
                    title: "List contents",
                    identifier: "ezconf-list-contents",
                    route: {
                        name: "eZConfList" // same route name of the one ad=
ded in the app plugin
                    }
                }
            }, 'platform'); // identifier of the zone called "Content" in t=
he UI
        },
    }, {
        NS: 'ezconfNavigation'
    });

    Y.eZ.PluginRegistry.registerPlugin(
        Y.eZConf.Plugin.NavigationPlugin, ['navigationHubViewService']
    );
});
=20

At this point, if you refresh you browser, you should see a new entry in= the Content zone called List contents. Clicking on this = link should even get you to the page defined in the previous step. And you can also notice that the nav= igation item gets a special style (a green bottom border) when the eZ= ConfList route is matched and that it loses this style if you naviga= te elsewhere.

Results and next step:

The resulting code can be seen in the 5_navigation tag on GitHub, this ste= p result can also be viewed as a diff between tags 4_view and 5_navigation.

The next step is then to build and display the content list.

------=_Part_3167_699259508.1485852259505--