• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tendoo CMS : How to require a module to be active

#1
Hi,
how are you going so far since the the first guide to create a module for tendoo cms 1.5 ?

As you may already know, Tendoo has a almost fully hookable UI and every features are actually part of modules. That why sometimes you may require a module to be active before proceeding, and by the same way, i'll introduce UI notices.

Are you ready ? here we go

Note : I assume that you already know how to create a tendoo module, if it's not the case, read this.

1. Download Tendoo from Github
This is the first step, before everything download tendoo from github.

2. Add conditionnal tag for the requirement

This is done through you module main file, while using "after_app_init" action hook. Modules are handled by a class named "Modules" which has only static methods. between thos methods, there is "is_active", which return a boolean if a module is enabled (true) or if it's not (false). Here is an example :

PHP Code:
<?php
class post_type extends CI_model
{
    function 
__construct()
    {
        
parent::__construct();
        
$this->events->add_action'after_app_init' , array( $this 'loader' ) );
    }
    
    function 
loader()
    {
        if( 
Modules::is_active'aauth' ) )
        {
            
// module is active lets proceed
        
}
        else
        {
            
$this->events->add_filter'ui_notices' , function( $notices ){
                return 
$notices[]        =    array(
                    
'msg'        =>        __'Aauth Module is required, please install or enable it' ),
                    
'type'    =>        'warning',
                    
'icon'    =>        'fa fa-times'
                
);
            });
        }
    }
}
new 
post_type

as you're seeing in this example, when the module is not enabled, we use a filter hook named "ui_notices", which let us add custom notices array inside the queue. This array should have thoses keys :
  • msg : for notice message

  • type : for notice type, you can use those type "warning", "info", "success"

  • icon : for notice icon, use font-awesome icon (example : "fa fa-times")

don't forget to return this updated array.

When the module is not active, a notice is being displayed on the dashboard like this :

[Image: module-requirement.png]

That's all for now.

Any question ?

Thanks for readding this Cool
NexoPOS 2.6.2 available on CodeCanyon.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.