UpgradeMODX connects its snippet-based widget to the default dashboard in a resolver. This usually works fine, but occasionally, the widget fails to show up on the dashboard.
It happened today and though I could see the widget listed in the dashboard’s grid, nothing I did would make it visible.
I looked at the modDashboardWidgetPlacement DB table and found that the user field for UpgradeMODX was set to 0. I set it to 1 (my user ID) and the widget showed up. Set it back to 0, and the widget disappeared again.
Looking at the DB, the user field clearly contains user IDs.
There are no usergroups or ACL entries related to the widgets or dashboard as far as I can tell.
So many questions:
What is the user field for and how does it work?
Is there a way to control the user field value in the Manager?
Should the user field be set when creating a
modDashboardWidgetPlacement record in code?
How did all of the users get modDashboardWidgetPlacement records set with their IDs for some of the widgets? I certainly didn’t do it.
How did I get user fields set to 0? Should that be prevented, or should 0 mean visible to all users?
I’m probably misunderstanding the whole process, but couldn’t find any core code that relates to these issues.
There seems to be a new feature in MODX3 that makes Dashboard widgets configurable on the dashboard itself.
If the option Customizable is checked for the dashboard, then the user can delete, add, reorder (drag and drop) or resize widgets directly on the dashboard. Every user can personalize his own dashboard.
I believe the entries with user set to 0 are the default settings for the dashboard.
If a new user logs into the manager, it creates a copy of these entries with user set to the user’s id.
If the user makes changes to his personal dashboard, then these changes are immediately saved to the database with his user id.
Thanks again. That makes sense, though it’s difficult to know what to do when installing a new widget.
Attaching it to the default dashboard, and assuming that the default dashboard is configureable (as it is on install) seems logical, but It seems crazy to create modDashboardWidgetPlacement records for potentially hundreds or even thousands of users, most of whom probably don’t have access to the Manager.
I wish I could find the code that creates those records when you attach a widget to a dashboard in the Manager to see if it somehow checks the users for Manager access, or just blindly creates the records for all users on the site.
But that removes all of the widgets from the dashboard and sets the widget value to 0 for the rest. I’ve stepped through the code in debug and it looks like everything is working, but obviously it’s not.
When this processor is called from the manager, then there is more data and the widgets field contains an array of all the widgets of the dashboard with all the detailed information of the widgets (id, rank, name, etc.)
I create the $options array based on default dashboard and the widget I’m installing. The idea of sending all the widgets came to me in the bathtub (where I get all my best ideas). I haven’t tried it yet, but it seems to me that if that were the only problem, my widget would still have been placed on the dashboard, which it wasn’t.
I think I’ve been overthinking this. It should be enough just to check to see if my widget is already attached, and if not, get the users listed in the placement table, and create a record for my widget for each of them, plus the user 0 record.
Actually, my first thought was to do something even simpler, like this:
/* Get objects here */
$widgets = array($widgetObject);