You are here

panopoly.install in Panopoly 7

Same filename and directory in other branches
  1. 8.2 panopoly.install

Install, update and uninstall hooks.

File

panopoly.install
View source
<?php

/**
 * @file
 * Install, update and uninstall hooks.
 */

/**
 * Implements hook_install().
 */
function panopoly_install() {
  _panopoly_install_help_block();
  _panopoly_install_administrator_role();
}

/**
 * Enable the Distribution Update Status Manager (distro_update) module.
 */
function panopoly_update_7101() {
  module_enable(array(
    'distro_update',
  ));
}

/**
 * Enable the core Block module and place the Help block.
 */
function panopoly_update_7102() {
  if (!module_exists('block')) {
    module_enable(array(
      'block',
    ));
  }
  _panopoly_install_help_block();
}

/**
 * Assign user 1 the "administrator" role.
 */
function panopoly_update_7103() {
  _panopoly_install_administrator_role();
}

/**
 * Helper function: add Help block to default/admin theme Help region.
 */
function _panopoly_install_help_block() {
  $default_theme = variable_get('theme_default', 'responsive_bartik');
  $admin_theme = variable_get('admin_theme', $default_theme);

  // Add the help block to the main theme help region.
  $blocks = array(
    array(
      'module' => 'system',
      'delta' => 'help',
      'theme' => $default_theme,
      'status' => 1,
      'weight' => 0,
      'region' => 'help',
      'pages' => '',
      'cache' => -1,
    ),
  );

  // If the admin theme is different than default theme, add the help
  // block to the admin them help region.
  if ($admin_theme != $default_theme) {
    $blocks[] = array(
      'module' => 'system',
      'delta' => 'help',
      'theme' => $admin_theme,
      'status' => 1,
      'weight' => 0,
      'region' => 'help',
      'pages' => '',
      'cache' => -1,
    );
  }

  // Add the blocks if they aren't already placed.
  foreach ($blocks as $block) {
    $region = db_select('block', 'b')
      ->fields('b', array(
      'region',
    ))
      ->condition('theme', $block['theme'])
      ->condition('module', $block['module'])
      ->condition('delta', $block['delta'])
      ->execute()
      ->fetchField();
    if (empty($region) || $region == -1) {
      db_merge('block')
        ->key(array(
        'theme' => $block['theme'],
        'module' => $block['module'],
        'delta' => $block['delta'],
      ))
        ->fields($block)
        ->execute();
    }
  }

  // Update the menu router information.
  menu_rebuild();
}

/**
 * Helper function: Assign UID 1 to 'administrator' role.
 */
function _panopoly_install_administrator_role() {

  // Load the administrator role created through features.
  if ($admin_role = user_role_load_by_name('administrator')) {

    // Assign user 1 the "administrator" role.
    db_merge('users_roles')
      ->key(array(
      'uid' => 1,
      'rid' => $admin_role->rid,
    ))
      ->fields(array(
      'uid' => 1,
      'rid' => $admin_role->rid,
    ))
      ->execute();
  }
}

Functions

Namesort descending Description
panopoly_install Implements hook_install().
panopoly_update_7101 Enable the Distribution Update Status Manager (distro_update) module.
panopoly_update_7102 Enable the core Block module and place the Help block.
panopoly_update_7103 Assign user 1 the "administrator" role.
_panopoly_install_administrator_role Helper function: Assign UID 1 to 'administrator' role.
_panopoly_install_help_block Helper function: add Help block to default/admin theme Help region.