logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Lemonldap:NG::Portal::MenuTab - Writing custom menu tabs for LemonLDAP::NG

Authors

       LemonLDAP::NG team <http://lemonldap-ng.org/team>

Bug Report

       Use       OW2       system       to       report       bug       or       ask        for        features:
       <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>

Description

       A MenuTab module handles displaying an additional tab to authenticated users.

   MethodsthatmustbeprovidedbyaMenuTabmodulerule

       This method must return the text of a rule that decides whether or not the tab is displayed to a user.

       Rules can be simple expressions such as "$uid eq "dwho"". If you want the tab to always be displayed,
       simply return a non-zero integer

           use constant rule => 1;

       name

       This method must return a name for the plugin. This name is used for ordering the tab in the
       "portalDisplayOrder" variable. It is not displayed to the user.

       display($req)

       This method is called by the portal in order to display the tab. It takes the current request object as a
       parameters, and must return a hash with the following subkeys:

       "logo": name of a fontawesome icon for the tab
       "name": user-displayed name of the tab, which should be translated in lang.json files.
       "id": HTML element id for the tab, must be unique
       "html": HTML content of the tab

       The "display" method can call helper functions such as "loadTemplate" to render a template

   Orderingofportaltabs
       You can use the "portalDisplayOrder" variable to change the order of portal tabs.

       Use the "name" of your plugin in this list, or use the special "_unknown" keyword to specify an order for
       all  plugin-managed  tabs.  If multiple modules are loaded, they will be displayed in the order they were
       loaded.

           portalDisplayOrder = Appslist ChangePassword CustomMenuTab LoginHistory \
               OidcConsents _unknown Logout

Download

       Lemonldap::NG is available at <https://lemonldap-ng.org/download>

Logging

       Logging  is  provided by "$self->logger" and "$self->userLogger". See Lemonldap::NG::Portal::Main::Plugin
       for a detailed description of logging levels.

Methods

AccessorsandmethodsprovidedbyLemonldap::NG::Portal::Main::Plugin
       p: portal object
       conf: configuration hash (as reference)
       logger alias for p->logger accessor
       userLogger alias for p->userLogger accessor
       error: alias for p->error method
       loadTemplate: render a HTML template from a .tpl file

   "Routes"management
       Like each module that inherits from Lemonldap::NG::Portal::Plugin, you can define dedicated routes  in  a
       MenuTab plugin.

       addAuthRoute: wrapper to Lemonldap::NG::Handler::PSGI::Try addAuthRoute() method
       addUnauthRoute: wrapper to Lemonldap::NG::Handler::PSGI::Try addUnauthRoute() method

Name

       Lemonldap:NG::Portal::MenuTab - Writing custom menu tabs for LemonLDAP::NG

Synopsis

         package Lemonldap::NG::Portal::Plugins::CustomMenuTab;

         use strict;
         use warnings;
         use Mouse;

         our $VERSION = '0.1';

         extends 'Lemonldap::NG::Portal::Main::Plugin';

         use constant name => "CustomMenuTab";

         has rule => (
             is      => "ro",
             lazy    => 1,
             builder => sub { $_[0]->conf->{customPluginsParams}->{customMenuRule} },
         );
         with 'Lemonldap::NG::Portal::MenuTab';

         sub display {
             my ( $self, $req ) = @_;
             return {
                 logo => "wrench",
                 name => "myplugin",
                 id   => "myplugin",
                 html => $self->loadTemplate($req, "mytemplate"),
             };
         }

         sub init {
             my $self = shift;

             # [your initialization stuff]

             return 1;
         }

         1;

See Also