This is a followup to some issues that were discovered by reviewers at #761956: Dashboard blocks and regions should not appear on the main blocks configuration page but which were not caused by the patch there.

The bug is that if you disable the dashboard module, you get a bunch of messages like these:

# The block Recent content was assigned to the invalid region dashboard_main and has been disabled.
# The block Search form was assigned to the invalid region dashboard_sidebar and has been disabled.
# The block Who's new was assigned to the invalid region dashboard_sidebar and has been disabled.

Then, turning the dashboard module back on, your data is lost - the dashboard is empty, and all blocks you previously had on there are now gone and need to be manually reassigned.

The proposed solution is by @BarisW (modified slightly by me): The dashboard should get its own theme, so that its blocks are stored separately and cannot be destroyed. This theme would basically be a blank "dummy theme", hidden in the admin UI (hidden = TRUE in the info file) which the dashboard module simply alters (via hook_system_info_alter) to be a subtheme of the site's current administrative theme.

I don't know for sure if this would work or not; probably the only way is to try writing the code. Besides solving the original bug, this would also:

  • Make possible to place two copies of the same block, one on the dashboard and one somewhere else in the admin area of your site. This seems to be a heavily requested feature but one that many people thought would require fieldable blocks (D8 material) to get.
  • Remove a fair amount of ugly code from the dashboard module.
  • Improve the UI for the region dropdown on the individual block configuration pages (possibly related to the discussion at #601932: Allow dashboard to limit available blocks). Right now, on a default Drupal install you have dropdowns labeled Bartik and Seven, and you have to look under Seven to place a block in a dashboard region, which is unintuitive. With this approach, there would be three region dropdowns: Bartik, Seven and Dashboard. This should make it a lot easier for people to figure out how to get a block on the dashboard.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bleen’s picture

This is an interesting proposal ... one thing to consider if we attempt this is what to do when a user changes the current admin theme. Would we switch the dummy theme to be a subtheme of the newly chosen admin theme? That would probably be ok, but it might get weird as certain settings may get inherited. Just something to keep in mind...

David_Rothstein’s picture

Right, that's the idea - the dummy theme would always be a subtheme of the current admin theme (or the default theme if your site isn't using an admin theme).

Are there specific settings that get inherited that you would be worried about? I think the idea here is mostly that we want all settings to be inherited, since from the user's perspective this should look exactly like their admin theme does, with the only difference being the list of regions that are displayed.

carlos8f’s picture

Status: Active » Needs review
FileSize
5.48 KB

chx has some code that copies blocks for use by the dashboard, by using hook_block_info_alter(). If that pans out, maybe we can use it. Although, I'm a little uneasy at the idea of having a 'fake' dashboard theme to assign these blocks to, and having that 'theme' persist even after the dashboard is disabled.

In the mean time I've written a patch that simply uses a variable_set/get to restore the blocks. I prefer not to get too crazy with this issue.

carlos8f’s picture

Ignore #3, it had some debug hunks.

Status: Needs review » Needs work

The last submitted patch, 950878-dashboard-disable.patch, failed testing.

carlos8f’s picture

Status: Needs work » Needs review

#4: 950878-dashboard-disable.patch queued for re-testing.

David_Rothstein’s picture

I haven't tried it, but that looks pretty reasonable to me.

When the module is enabled or disabled, it looks like that code needs to run in a specific order with respect to block rehashing in order to work correctly - is it relying on module weights for that, I guess?

Maybe we can move the theme idea to @sun's new issue at #951212: Dashboard blocks should be configured completely independently from the default/admin theme blocks instead.

carlos8f’s picture

Rehash on hook_flush_caches() was introduced in #235673: Changes to block caching mode not caught. There's no ordering/weighting problem as far as I know: rehash always comes after hook_enable/disable, for the reason that drupal_flush_all_caches() always comes after module_enable/disable. So the {block} table will not change until after all the enabling and disabling is done. That allows us to stash the blocks even if the providing module(s) are disabled already, as long as they are part of the same enable/disable batch.

David_Rothstein’s picture

In that case I think this patch is pretty much ready to be committed. I tested it out, and it seems to work fine. I was impressed that it even caught (and correctly handled) the edge case where blocks that were once on the dashboard had been moved to another part of the admin theme during the time when the dashboard module was disabled :)

The only small thing I noticed was that in this query in hook_disable():

+  $result = db_select('block', 'b')
+    ->fields('b')
+    ->condition('b.region', dashboard_regions(), 'IN')
+    ->execute();

we are loading all rows from the database, but that seems unnecessary since we only wind up using a couple of them.

carlos8f’s picture

we are loading all rows from the database, but that seems unnecessary since we only wind up using a couple of them.

I assume you mean 'columns', not 'rows' :)

David_Rothstein’s picture

Er, yes, I probably had my head turned 90 degrees when I wrote that... in which case they switch places anyway :)

David_Rothstein’s picture

Title: Disabling the dashboard module permanently removes all blocks from the dashboard (dashboard needs its own subtheme) » Disabling the dashboard module permanently removes all blocks from the dashboard
FileSize
4.85 KB

Rerolled to fix that issue.

I think this is basically RTBC. Looking at dashboard_enable(), though, I wonder why we ever want to check global $theme_key - that seems a little fragile, to make it depend on the theme of the current request (especially since this is inside an API function that might be called outside of a web browser, even)?

On the other hand, it's not much worse than what some of the other dashboard code does, and I don't really know how to fix it in the context of this issue alone.

carlos8f’s picture

Maybe we can get rid of that (checking $theme_key) if it's safe to assume 'admin_theme' is always set. However, throughout core there doesn't seem to be a default value for the variable, so instead of simply aborting, there's a fallback. And also, dashboard.module doesn't even use 'admin_theme'! But I was conscious here that hook_enable() is frequently run outside the admin theme, thus the variable check.

Since this is a simple re-roll of my patch, I think we can RTBC after the bot approves it.

carlos8f’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Right, I agree we need something more than 'admin_theme' - I was just wondering if we couldn't use 'theme_default' or something as the fallback instead. However, there is no guarantee it would be better than the current behavior. For the purposes of this issue, what we have is probably the best we can do.

Here is a quick reroll because I realized that on hook_uninstall() we should be deleting this variable so it doesn't litter the database forever. (I'm not changing the RTBC status since this is a pretty trivial addition to the patch.)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

carlos8f’s picture

Title: Disabling the dashboard module permanently removes all blocks from the dashboard » (incomplete commit) Disabling the dashboard module permanently removes all blocks from the dashboard
Status: Fixed » Reviewed & tested by the community
FileSize
2.31 KB

Wait a sec :P the added file (dashboard.install) was not committed, and it broke HEAD testing. Here's the dashboard.install alone as a patch.

chx’s picture

Title: (incomplete commit) Disabling the dashboard module permanently removes all blocks from the dashboard » [HEAD BROKEN] Disabling the dashboard module permanently removes all blocks from the dashboard
Priority: Major » Critical
webchick’s picture

Title: [HEAD BROKEN] Disabling the dashboard module permanently removes all blocks from the dashboard » Disabling the dashboard module permanently removes all blocks from the dashboard
Priority: Critical » Major
Status: Reviewed & tested by the community » Fixed

Oh, how I despise you, CVS.

Committed to HEAD. Very sorry. :(

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.