Don't allow multiple widgets

Hello,

today i startet working with elgg. It's a very nice script, but i have one big problem:

Why is it possible, that users can add multiple instances of one widget to their dashboard or profile page? In the code i see this note:

 

 

* @param true|false $multiple Whether or not multiple instances of this widget are allowed on a single dashboard (default: false)

I also found a ticket about this problem, but no solution to resolve this problem.

Can someone tell me more about this problem?

  • The parameter is currently being ignored. That's the problem.

  • Thank you for the answer, do you know when it will be resolved?

  • Probably when someone submits a patch to Trac to fix the problem. When I think of the current list of bugs and desirable new features, I would imagine that this one would rank low.

    If someone submits a simple patch, however, then a fix might happen a lot more quickly.

  • Ok, perhaps i will find the bug tomorrow.

    Can you give me a hint: Where ist the place, where the list of available widgets is being generated?

  • That trac item that I linked to links to this item that has further discussion on this: https://trac.elgg.org/elgg/ticket/590

  • So, here is a solution, which works fine for me:

    In the \views\default\canvas\layouts\widgets.php:

    On line 15 add $available_widgettypes = get_widget_types(true);

    Change the first foreach-loop change $widgettypes to $available_widgettypes

    In the \engine\lib\widgets.php change the function get_widget_types() to:

    function get_widget_types($only_available_widgets = false) {
               
                global $CONFIG;
                if (!empty($CONFIG->widgets)
                    && !empty($CONFIG->widgets->handlers)
                    && is_array($CONFIG->widgets->handlers)) {
                       
                        $context = get_context();
                       
                        if($only_available_widgets){
                            $user_guid = page_owner();
                            $user_widgets = get_entities_from_private_setting_multi(array(
                                                        'context' => $context), "object", "widget", $user_guid, "", 10000);
                        }
                                                   
                        foreach($CONFIG->widgets->handlers as $key => $handler) {
                           
                            if($only_available_widgets){
                                foreach($user_widgets as $user_widget) {
                                    if($user_widget->handler == $key && $handler->multiple == false) {
                                        unset($CONFIG->widgets->handlers[$key]);
                                    }
                                }
                            }
                           
                            if (!in_array('all',$handler->context) &&
                                !in_array($context,$handler->context)) {
                                    unset($CONFIG->widgets->handlers[$key]);
                            }
                        }
                       
                        return $CONFIG->widgets->handlers;
                       
                    }
                   
                return array();
               
            }

     

  • You should consider submitting this as a patch to trac. If you have difficulty creating an account there, let me know.

  • I did the above but have found the following;

    Friends Activity widget renamed "river_widget_friends"

    In dashboard "Edit Page" doesn't action, in fact in profile 50%+ of the widgets seem to go back to what I would assume are their original names, so I will undo the above changes and just hope users don't add multiple widget instances on their profiles. :)

  • @Cash: In trac I only get "No handler matched request to /registe"

    @Rob: Sounds strange. In my Installation I cant't reproduce your error.