Jump to content

Attach Plugin To A Module


Blesta Addons

Recommended Posts

i'm coding a plugin , and i want this plugin to add some extra tabs in my module .

 

is this possible ?

 

i have looked at the event , but really i have not found a solution .

 

my modules has some tabs (for admin/clients)

 

i want to make the plugins add extra tabs (templates also)  to the module .

 

 

Link to comment
Share on other sites

I suppose you would need to make your module aware of the plugin and load those extra functions when/if they are meant to be applied.

 

Loading a plugin is pretty straight forward from a module, adding tabs is a little more weird but there was a conversation I had with Cody about this back in Alpha. From memory you had to define the tabs inside __call() in order to override the pre-defined definitions.

 

I'm pretty sure you were in that group so this might be the best place to see how it works..

 

http://staging.blesta.com/forums/index.php?/topic/87-admin-tabs-best-approach/

 

If I understand correctly, you could load your plugin from your module in the __call() method, then add extra tabs as required from the plugins own classes/methods.

Link to comment
Share on other sites

I suppose you would need to make your module aware of the plugin and load those extra functions when/if they are meant to be applied.

 

Loading a plugin is pretty straight forward from a module, adding tabs is a little more weird but there was a conversation I had with Cody about this back in Alpha. From memory you had to define the tabs inside __call() in order to override the pre-defined definitions.

 

I'm pretty sure you were in that group so this might be the best place to see how it works..

 

http://staging.blesta.com/forums/index.php?/topic/87-admin-tabs-best-approach/

 

If I understand correctly, you could load your plugin from your module in the __call() method, then add extra tabs as required from the plugins own classes/methods.

 

 

Hello scott ,

 

thanks for the replay . i have already see that threa in the past ... but really i have not found way to add extra tabs to the module X if the plugin Y installed .

 

i'm able to check if the plugin Y installed and then add extra tabs from the module .

 

Now i want like to force the plugin add extra tabs in the module X when it run by user .

 

like adding link to main navigation .

 

i see is possible to call the plugin X function with the above thred (not yet tested by me) , but i'm asking for thing to see if possible or not

 

just to not loss time in testing something that will not work !!!

 

waiting the staff to confirm  or deny .

Link to comment
Share on other sites

The module will have to support the functionality and views for those tabs, and check if the required plugin is installed before loading them. Cody or Tyson may be able to comment on how you check if a plugin is installed.

 

i have the code to check if plugin is installed ...

 

left now how to attach the tabs from plugin to module .

Link to comment
Share on other sites

left now how to attach the tabs from plugin to module .

 

I started working on this exact scenario, basically, I just loaded all the classes that I wanted to be able to attach  a tab, then cycle each one and return back a tab definition, finally returning back the tab list as per normal. It's not hugely pretty (I did it with classes in a single module, but a plugin should also work).

 

I can paste a snippet of the logic here if you like, however, I can't recall the state of it as I haven't done any coding on the module for a little while.

Link to comment
Share on other sites

Okay, after playing with this a little more, there are some complications.

 

I can list the plugins on the system, and I can even use a regex to match against my own written plugins using the 'dir' value of the plugin object, (means I can target my own matching plugins by name), however, it doesn't seem to have a nice method of loading a model that is part of the plugin outside the plugin itself.

 

The idea I have so far is this. (Don't copy and paste this as there are errors, it is cludged from a mess I have written already).

 

 

public function getAdminTabs($package)
{
   $admin_tabs = array(
      // Add default tabs for module
   );
   Loader::loadComponents($this, array("Record"));
 
   foreach($this->Record->select()->from("plugins")->where('dir', 'LIKE', 'my_prefix_%')->fetchAll() as $plugin)
   {
      // Extremely ugly code to get the class name from the module directory.
      $plugin_tabs = sprintf("%s::%sAdminModuleTabs\n", $plugin->dir, preg_replace('/_/', '', $plugin->dir));
      
      array_push($admin_tabs, $plugin_tabs::getAdminTabs($package));
   }
 
   return $admin_tabs;
}

 

 

There are problems with this of course.. 1) It doesn't actually work. :(

 

I think one of the main issues is that I would like the following.

 

1) Be able to load a model from any plugin/gateway/module in the system from anywhere else. (Should I just use a standard include (or include_once)?).

2) Be able to use a class and method (class::method() or similar) when returning a list of tabs to be present in getadmintabs() as this would allow for adding tabs to other modules anywhere else in the system.

 

----

 

Based on the above, I can manually include the plugin class, then call the getAdminTabs() method and return a list of tabs that need to be added

 

 

public function getAdminTabs($package)
{
    Loader::loadComponents($this, array("Record"));
    $admin_tabs = array(
        // Default module tabs that you want
    );
    $plugins = $this->Record->select()->from("plugins")->where('dir', 'LIKE', 'my_plugin_prefix_%')->fetchAll();
    foreach($plugins as $plugin)
    {
        $class = sprintf('%sAdmintabs', preg_replace('/_/', '', $plugin->dir));
        include_once(sprintf('%s/plugins/%2$s/models/%2$s_admintabs.php', getcwd(), $plugin->dir));
        $admin_tabs = array_merge($admin_tabs, $class::getAdminTabs($package));
    }
    return $admin_tabs;
}

 

 

In my plugin model I have

 

 

public static function getAdminTabs($package)
{
    return array(
        'MyPluginModel::plugin_tab1' => 'Plugin tab 1',
    );
}

 

 

Of course, the 'MyPluginModel::plugin_tab1' will never work as it's not a valid path anywhere.

 

I think we need a bump/push from the dev guys to figure this one out a little more.

 

 

Link to comment
Share on other sites

Hello Scott ,

 

thanks for the share , i have get some new knowledge for this subject .

 

your methode is not what i want  .

 

you want to includes the tabs plugins from module by module code . i want the reverse .

 

includes tabs in the module without touching the module class .  (something semilar to wordpress)

 

for example i want a plugin to attach thier tabs auto to the module X (if installed) without touching the class module .

 

as i see this is not possible no, i have fetched the module.php for some rules or code that can do this .

 

like wordpress has a registred function like head() body() , we can include some extra data to this placement with the plugin itself .

 

i have see some plugins of whm** has the same rules , the plugin attach some extra tabs and function to another plugin/module .

 

i hope the idea is now clear . we will waiting the blesta staff commenting this . this is a modular code:)

Link to comment
Share on other sites

This sounds more like you want to be able to register an event for the call to getAdminTabs so any plugin/module/whatever can return a result and be included in the tab list.

 

This of course, also requires the ability to make a call to the plugin for the tab content which is something that doesn't appear to be easy to achieve. (This makes my head spin).

 

This sounds absolutely AWESOME if it could be done, (Thinking kind of like how the search system get's extended in plugins).

 

 

Yep, this is going to need some dev help for sure.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...