How To Enable a Block During Module Installation In Drupal

0
Your rating: None

Many often, you may require a block to show up automatically when a module is installed. This is fairly straightforward, and is achieved through a query that inserts the block settings directly into the blocks table. The query goes within hook_install(), located in your module’s .install file.

Here is an example of the user module enabling the user login block when Drupal is being
installed (see modules/system/system.install):

db_query("INSERT INTO {blocks} (module, delta, theme, status) VALUES
   ('user', 0, '%s', 1)", variable_get('theme_default', 'garland'));

The above database query inserts the block into the blocks table and sets its status to 1 so that it is enabled.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India