You are here

multipurpose_corporate_profile.profile in Multipurpose Corporate Profile 7

Same filename and directory in other branches
  1. 8 multipurpose_corporate_profile.profile

Enables modules and site configuration for a standard site installation.

File

multipurpose_corporate_profile.profile
View source
<?php

/**
 * @file
 * Enables modules and site configuration for a standard site installation.
 */

/**
 * Select the current install profile by default.
 */
if (!function_exists("system_form_alter")) {

  /**
   * Implements hook_form_alter().
   */
  function system_form_install_select_profile_form_alter(&$form, $form_state) {
    foreach ($form['profile'] as $profile_name => $profile_data) {
      $form['profile'][$profile_name]['#value'] = 'multipurpose_corporate_profile';
    }
  }
}

/**
 * Implements hook_install_tasks().
 */
function multipurpose_corporate_profile_install_tasks($install_state) {
  $tasks = array();
  $tasks['multipurpose_corporate_profile_custom_settings'] = array(
    'display' => FALSE,
  );
  $tasks['multipurpose_corporate_profile_blocks_turning'] = array(
    'display' => FALSE,
  );
  $tasks['multipurpose_corporate_profile_public_files_copy'] = array(
    'display' => FALSE,
  );
  return $tasks;
}

/**
 * Our custom task.
 *
 * Custom settings help to display content correctly.
 *
 * @param array $install_state
 *   An array of information about the current installation state.
 *
 * @throws \Exception
 */
function multipurpose_corporate_profile_custom_settings(array $install_state) {
  $node = node_load(3);
  if (!empty($node)) {
    $node->path = array(
      'alias' => 'about-us',
      'pathauto' => FALSE,
      'language' => 'und',
    );
    node_save($node);
  }
  $node = node_load(6);
  if (!empty($node)) {
    $node->path = array(
      'alias' => 'contact-us',
      'pathauto' => FALSE,
      'language' => 'und',
    );
    node_save($node);
  }
  variable_set('menu_block_2_parent', 'main-menu:468');
}

/**
 * Our custom task.
 *
 * Enable and turning blocks.
 *
 * @param array $install_state
 *   An array of information about the current installation state.
 */
function multipurpose_corporate_profile_blocks_turning(array $install_state) {
  $modules = array();
  if (!module_exists('features_blocks')) {
    $modules[] = 'features_blocks';
  }
  if (!module_exists('features_menu')) {
    $modules[] = 'features_menu';
  }
  if (!empty($modules)) {
    module_enable($modules);
  }
}

/**
 * Our custom task.
 *
 * Copy public files for default theme.
 *
 * @param array $install_state
 *   An array of information about the current installation state.
 */
function multipurpose_corporate_profile_public_files_copy(array $install_state) {
  $source = 'profiles/multipurpose_corporate_profile/node_export_assets/adaptivetheme/';
  $res = 'sites/default/files/adaptivetheme/';
  multipurpose_corporate_profile_recurse_copy($source, $res);
  $image_source = 'profiles/multipurpose_corporate_profile/node_export_assets/logo.png';
  $image_res = 'sites/default/files/logo.png';
  copy($image_source, $image_res);
  $image_source = 'profiles/multipurpose_corporate_profile/node_export_assets/img.jpg';
  $image_res = 'sites/default/files/img.jpg';
  copy($image_source, $image_res);
  $source = drupal_realpath('profiles/multipurpose_corporate_profile/node_export_assets/default_blog_pic.jpg');
  $file = (object) array(
    'uid' => 1,
    'uri' => $source,
    'filemime' => file_get_mimetype($source),
    'status' => 1,
  );

  // We save the file to the root of the files directory.
  drupal_mkdir('public://default_images/');
  $file = file_copy($file, 'public://default_images/default_blog_pic.jpg');
}

/**
 * Recursive copy.
 *
 * @param string $src
 *   - Source folder with files.
 * @param string $dst
 *   - Destination folder.
 */
function multipurpose_corporate_profile_recurse_copy($src, $dst) {
  $dir = opendir($src);
  @mkdir($dst);
  while (FALSE !== ($file = readdir($dir))) {
    if ($file != '.' && $file != '..') {
      if (is_dir($src . '/' . $file)) {
        multipurpose_corporate_profile_recurse_copy($src . '/' . $file, $dst . '/' . $file);
      }
      else {
        copy($src . '/' . $file, $dst . '/' . $file);
      }
    }
  }
  closedir($dir);
}