| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | dashboard.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | needs backport to D7 |
Issue Summary
Problem/Motivation
There is an issue with the Devel module conflicting with the Dashboard module. At admin/structure/dashboard blocks can be successfully placed into dashboards regions. However, at admin/dashboard dragged blocks don't retain their new location. This is because the Devel module, which has the "switch user" block, is converting underscores to hyphens when blocks are rearranged on the dashboard, affecting block CSS IDs and block deltas.
Steps to replicate:
- Go to the block admin style UI (admin/structure/dashboard) and move the 'switch user' block into one of the dashboard regions (sidebar).
- Go to the dashboard UI (admin/dashboard). The block is in the sidebar.
- Click configure.
- Drag the block to the main content region.
- Click 'Done'.
Proposed resolution
Add module-<module name> and delta-<delta> classes to enabled blocks.
Patch in #16 implements this fix for D7 and D8.
Remaining tasks
- Patch in #16 is RTBC.
- Patch needs backport to D7.
User interface changes
Two additional CSS classes will be available on dashboard blocks: module-modulename and delta-N. Blocks will be correctly ordered based on these classes.
API changes
None.
Original report by [joachim]
At admin/structure/dashboard I can place blocks into two dashboard regions, yet at admin/dashboard I still appear to be free to move them around to either region ... except that when I click 'Done', the ones set at the first page snap back.
This is confusing. In fact, the whole business of having two pages is confusing -- the UI doesn't explain why there are two and how they relate to each other.
Comments
#1
I think this is mostly a duplicate of these issues:
#930670: Table-based dashboard admin page should be linked to from the dashboard only (not from the rest of the admin UI)
#601932: Allow dashboard to limit available blocks
(The UI really isn't finished yet, basically.)
But what do you mean by this?
What exactly happens, and what would you expect to happen? The drag-and-drop functionality on the dashboard seems to work for me, and when I click "Done" it remembers all the changes I just made and uses them.
#2
> (The UI really isn't finished yet, basically.)
Ah right.
> What exactly happens, and what would you expect to happen?
1. I go to the block admin style UI and put a block into one of the dashboard regions.
2. Then I go to the dashboard UI and see it there. I can move it to the other region or to the reserve at the top.
3. Then I click 'Done', and the block is back where it started.
If the intention is that the block admin style UI is a sort of super-admin settings page where some blocks can be locked into place, then the regular dashboard UI needs to enforce that properly and not let me drag the blocks around that it's not going to let me change.
But then, part of the problem as you say is that the UI is finished and I am not sure what these two pages are meant to accomplish in tandem.
#3
By "back where it started", you mean back to where it was after step #1? That's definitely not what happens for me... when I try it, after clicking "Done" the block is wherever I put it last (i.e., wherever I put it at the end of step #2).
Do you have a more exact set of steps to reproduce?
The block-admin-style page is not meant to be a super-admin page, just an alternative interface for doing the same thing (mainly for accessibility reasons, although there are other potential uses too). I think most of the confusion around this can hopefully be fixed with #930670: Table-based dashboard admin page should be linked to from the dashboard only (not from the rest of the admin UI), or perhaps with some additional tweaking on top of that.
#4
Yes, the block goes to where it was put on the *other* admin page.
Steps to reproduce, which I've just done on a totally clean CVS updated D7, using Bartik as the admin theme:
1. admin/structure/dashboard -- move the 'switch user' block into dashboard sidebar.
2. admin/dashboard -- notice the block is in the sidebar
3. click configure
4. drag the block to the main content region
5. click 'Done'
6. notice the block is in the sidebar again.
This seems to only work with some blocks, and I can't see the pattern yet. 'Who's new' sticks where I put it, for instance.
Also, probably unrelated, but I get several things that look like blocks but just say '(empty)' and this warning several times:
# Notice: Undefined index: switch-user--2 in dashboard_page_build() (line 162 of /Users/joachim/Sites/7-drupal/modules/dashboard/dashboard.module).
#5
Hm, I can't reproduce that with any core blocks, but installing the Devel module (which has the "switch user" block) I can.
It looks like what's happening is that the Devel module blocks are defined with an underscore in their deltas (for example, 'switch_user' and 'execute_php'). That underscore seems to get converted to a hyphen when the blocks are being rearranged on the dashboard, and otherwise messes things up badly. Not sure what's going on - probably has something to do with http://api.drupal.org/api/function/drupal_html_id/7 converting block deltas into IDs with slightly different names, and the dashboard module getting confused by that.
#6
I wonder if the patch I posted a long time ago at #720544: Dashboard markup and theme functions need work would help here.
#7
To update the order of blocks when managed through the dashboard customize interface, the block's CSS id is used as identifier for an individual block. The CSS id is generated by drupal_html_id(), which (in short and amongst other transformations), does the following (with block-<MODULE>-<DELTA> as id):
This basically is irreversible. I don't think there is a reliable way to take an id generated by drupal_html_id() and deduct the original module name and delta from this value. This also means that the scope of this issue is not restricted to just the deltas: I'm guessing that module names with an underscore will also confuse dashboard.
For example, a block CSS id "block-foo-bar-boo" could mean module = "foo" and delta = "bar_boo" (or even "bar-boo" or "baR bOo"), or it could mean module = "foo_bar" and delta = "boo". Add to that the fact that hook_block_info doesn't really impose much restrictions on allowed values for delta, and the fact that drupal_html_id() can add --<sequential_number> for ids that appear more than once on a page...
Attached is a patch that adds the module-<module name> and delta-<delta> classes to enabled blocks when displayed on the dashboard (the inactive blocks already have these classes). It's an improvement over the current situation (it fixes the issue reported in the OP), but the issue remains that CSS identifiers come with restrictions on what characters can be used, and the block's delta key does not have these restrictions, so trying to pass this data via the class attribute remains icky unless we can reliably encode/decode these or change the documentation on hook_block_info so it imposes additional constraints on the delta attribute...
#8
Sorry, didn't mean to change the status. I tested this patch and it worked for the Devel module issues. Why wasn't it released with D7?
#9
#10
> Why wasn't it released with D7?
It needs further review...
I'm a bit wary of the need to implement a theme preprocess hook :/
Is there no other way to do this?
#11
Subscribing
#12
This bug is not major. However, the patch looks good. RTBC if bot passes against D8.
#13
#7: 936798-dashboard-block-ordering.patch queued for re-testing.
#14
bot passes, so like sun said i set it to RTBC
#15
Subscribe
#16
Argh this bit me again today. All my dashboard blocks vanished after updating to 7.8 :(
Rerolled the patch against the latest 8.x, and fixed some typos.
#17
Works.
After applying the patch to recent D-7.x the empty blocks on the dashboard can be deleted.
#18
Same problem when using user_dashboard contrib module, because it copies this code.
Makes dashboard fairly useless with contributed modules with underscores or block delta's with underscores or dashes.
#19
Thanks, looks good!
That said: So much to HTML IDs. Good bye! We won't miss you.
#20
sub
#21
I'm not sure why we can't add some generic classes in the block module here rather than the preprocess - seems not impossible that contrib or custom modules might want to be able to identify blocks in a similar way. If there's a good reason for that (like that never being likely to happen and it adding extra stuff to block module only so dashboard can use it later, which is the only reason I can think of), it should be added to the preprocess function as a comment.
#22
This patch got rid of the error, but the block will not reorder. When I save it goes back to it's original position before being drug.
Any ideas?
#23
The patch worked against Drupal 7.12 and I can now move my blocks around in the customize dashboard screen and have it remember them when I click "done".