Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashbboard map not visible on fresh install #273

Closed
mstenta opened this issue Apr 13, 2020 · 6 comments
Closed

Dashbboard map not visible on fresh install #273

mstenta opened this issue Apr 13, 2020 · 6 comments
Labels

Comments

@mstenta
Copy link
Member

mstenta commented Apr 13, 2020

Spun off as a separate issue from #272

What's happening is: the farmOS theme is being installed BEFORE the farm_map module. So farm_theme_block_info_alter() is running, but the block is not yet available to alter. So... the block doesn't show up again until farm_theme_block_info_alter() runs a SECOND time after the installation. This happens by visiting the Admin > Structure > Blocks page, or by clearing the cache.

@mstenta
Copy link
Member Author

mstenta commented Apr 13, 2020

Hmm - thinking about this more...

farm_map actually is enabled before farm_theme. It is a dependency of farm_log, which is a dependency of farm, so it should already be enabled before theme_enable('farm_theme') is called.

Need to give this more thought...

@mstenta
Copy link
Member Author

mstenta commented Apr 13, 2020

I put a breakpoint in farm_map_block_info() and in farm_theme_block_info_alter() and ran a fresh install. The farm_map_block_info() breakpoint was hit when the installation was at 100% of the "Install profile" step, and again (twice actually) at the end of the "Install optional modules" step. The farm_theme_block_info_alter() hook never fires. And the map is not displayed on the dashboard.

@mstenta
Copy link
Member Author

mstenta commented Apr 13, 2020

Looking into exactly when hook_block_info and hook_block_info_alter() are invoked... it appears to happen either a) when you visit the Blocks admin page (/admin/structure/blocks), or when caches are flushed (but critically: only for themes that are enabled in the {system} table!) See: https://git.drupalcode.org/project/drupal/-/blob/460ff5dc3c577d6139b37bc3467ab5b742371626/modules/block/block.module#L987

So this is related to #272

And that explains why it hasn't been an issue on Farmier-hosted farmOS instances:

However, once I learned that it was the install_profile variable that was to blame, I remembered: Farmier sets that variable in settings.php, so it is always farm

(#272 (comment))

The theme is enabled on Farmier instances, and the cache is cleared after they are created. So the map works there.

So to fix this... maybe we just need to call that block_flush_caches() function after we enable the theme?

@mstenta
Copy link
Member Author

mstenta commented Apr 14, 2020

maybe we just need to call that block_flush_caches() function after we enable the theme?

I tried this inside the new farm_install_theme() function (5c30ea3), but it didn't seem to make a difference. Might be worth retrying with Xdebug to figure out why...

@mstenta
Copy link
Member Author

mstenta commented Apr 14, 2020

I tried this inside the new farm_install_theme() function (5c30ea3), but it didn't seem to make a difference. Might be worth retrying with Xdebug to figure out why...

Stepped through the install process with XDebug and discovered why this wasn't working. The code was running, but drupal_alter() only runs the _alter() hooks coming from the currently active theme, which during the install process is seven.

I was able to make it work with the following code in a new install tasks farm_install_blocks:

/**
 * Callback for farmOS blocks install task.
 */
function farm_install_blocks() {

  // Update blocks for the farmOS theme.
  // We need to run _block_rehash() so that hook_block_info_alter() in
  // farm_theme has a chance to alter blocks provided by other farmOS modules
  // (eg: to enable/insert them into regions).
  // We need to override the global $theme variable and manually include the
  // theme's template.php file so that drupal_alter() runs its alter hooks.
  // @see https://github.com/farmOS/farmOS/issues/273
  global $theme;
  $old_theme = $theme;
  $theme = 'farm_theme';
  include_once drupal_get_path('theme', $theme) . '/template.php';
  _block_rehash($theme);
  $theme = $old_theme;
}

It feels a bit hacky, but it works. I would like to see if there's a better way to load template.php.

@mstenta
Copy link
Member Author

mstenta commented Apr 14, 2020

I committed this. We can improve/iterate in the future if we need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant