Skip to content

Instantly share code, notes, and snippets.

@larowlan
Created February 6, 2014 04:02
Show Gist options
  • Save larowlan/8838225 to your computer and use it in GitHub Desktop.
Save larowlan/8838225 to your computer and use it in GitHub Desktop.
Place a block using update hook - Drupal 7
<?php
/**
* Place the views exposed search block.
*/
function YOURPROFILE_update_7001() {
$default_theme = variable_get('theme_default', 'YOURTHEME');
// Enable some standard blocks.
$blocks = array(
array(
'module' => 'views',
'delta' => 'a8f68d4dde938b83bf7656900d06a5bc',
'theme' => $default_theme,
'status' => 1,
'weight' => 10,
'region' => 'header',
'pages' => 'search*',
'cache' => -1,
'title' => '',
),
);
foreach ($blocks as $block) {
db_merge('block')
->key(array(
'theme' => $block['theme'],
'module' => $block['module'],
'delta' => $block['delta'],
))
->fields($block)
->execute();
}
}
@jenlampton
Copy link

Thanks for this!
It's still helping those who google, 7 years later!

@larowlan
Copy link
Author

😂 ha ha

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