Jump to content

Registering Plugin Action - widget_client_home


Adam

Recommended Posts

Hello,

I was trying to register an action for my plugin so a widget will appear on the client dashboard (widget_client_home). What I found is that the URL can not contain any GET parameters as jQuery fails with the following via the browser. 

public function getActions() {
    return array(
...
        array(
            'action' => 'widget_client_home',
            'uri'    => 'plugin/cerberus/client_tickets/index/?whole_widget=true',
            'name' => Language::_('cerberus.widget.title', true),
        ),
...
    );
}
Uncaught Error: Syntax error, unrecognized expression: #widget_container_plugin_cerberus_client_tickets_index_?test=blah
    at Function.ot.error (jquery.min.js:4)
    at gt (jquery.min.js:4)
    at kt (jquery.min.js:4)
    at Function.ot [as find] (jquery.min.js:4)
    at init.find (jquery.min.js:5)
    at init (jquery.min.js:4)
    at x (jquery.min.js:4)
    at Object.$.blestaRequest.widget_id [as success] (jquery-client-3.5.0.js:113)
    at l (jquery.min.js:4)
    at Object.fireWith [as resolveWith] (jquery.min.js:4)

 

If you look in app/client_controller.php the issue is not specifically with the URL but rather the method used to generate the $key/unique identifier for the that widget.

 

Knowing that, I figured we could just take the SHA1 hash of the URL as that would give us a unique string with no special character issues. It also reduces memory since the key is fixed length and not variable with the URL.

diff --git a/app/client_controller.php b/app/client_controller.php
index cdc1dbc..752793e 100644
--- a/app/client_controller.php
+++ b/app/client_controller.php
@@ -95,7 +95,7 @@ class ClientController extends AppController
         // Load widgets configured for display
         $plugin_actions = $this->PluginManager->getActions($this->company_id, $widget_location, true);
         foreach ($plugin_actions as $plugin) {
-            $key = str_replace('/', '_', trim($plugin->uri, '/'));
+            $key = sha1($plugin->uri);
             $widgets[$key] = [
                 'uri'=>$this->base_uri . $plugin->uri
             ];

 

-Adam

 

Edited by Adam
added sample code for the getActions function
Link to comment
Share on other sites

27 minutes ago, Blesta Addons said:

Not sure if this possible, but what i do normally is to the set request inside the widget itself .

are you want to make sorting table by indexes or something similar ?

 

I could move away from using GET parameters and make it part of the route, etc. But I still think this is a bug in Blesta (or something they should document), hence the bug report and patch. Lets see what @Paul and folks say.

 

-Adam

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 1 month later...

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...