commerce_kickstart.profile 10.8 KB
Newer Older
1 2
<?php

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/**
 * Implements hook_image_default_styles().
 */
function commerce_kickstart_image_default_styles() {
  $styles = array();
  $styles['frontpage_block'] = array(
    'name' => 'frontpage_block',
    'effects' => array(
      1 => array(
        'label' => 'Scale and crop',
        'help' => 'Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.',
        'effect callback' => 'image_scale_and_crop_effect',
        'dimensions callback' => 'image_resize_dimensions',
        'form callback' => 'image_resize_form',
        'summary theme' => 'image_resize_summary',
        'module' => 'image',
        'name' => 'image_scale_and_crop',
        'data' => array(
          'width' => '270',
          'height' => '305',
        ),
        'weight' => '1',
      ),
    ),
  );

  return $styles;
}

32 33 34 35 36 37
/**
 * Implements hook_form_alter().
 *
 * Allows the profile to alter the site configuration form.
 */
function commerce_kickstart_form_install_configure_form_alter(&$form, $form_state) {
38 39 40 41
  // When using Drush, let it set the default password.
  if (drupal_is_cli()) {
    return;
  }
42 43
  // Set a default name for the dev site and change title's label.
  $form['site_information']['site_name']['#title'] = 'Store name';
44
  $form['site_information']['site_mail']['#title'] = 'Store email address';
45
  $form['site_information']['site_name']['#default_value'] = st('Commerce Kickstart');
46 47 48

  // Set a default country so we can benefit from it on Address Fields.
  $form['server_settings']['site_default_country']['#default_value'] = 'US';
49

50 51 52 53 54 55
  // Use "admin" as the default username.
  $form['admin_account']['account']['name']['#default_value'] = 'admin';

  // Set the default admin password.
  $form['admin_account']['account']['pass']['#value'] = 'admin';

56 57 58 59 60
  // Hide Update Notifications.
  $form['update_notifications']['#access'] = FALSE;

  // Add informations about the default username and password.
  $form['admin_account']['account']['commerce_kickstart_name'] = array(
61 62
    '#type' => 'item',
    '#title' => st('Username'),
63
    '#markup' => 'admin'
64 65
  );
  $form['admin_account']['account']['commerce_kickstart_password'] = array(
66 67
    '#type' => 'item',
    '#title' => st('Password'),
68
    '#markup' => 'admin'
69 70
  );
  $form['admin_account']['account']['commerce_kickstart_informations'] = array(
71
    '#markup' => '<p>' . t('This information will be emailed to the store email address.') . '</p>'
72
  );
73 74
  $form['admin_account']['override_account_informations'] = array(
    '#type' => 'checkbox',
75
    '#title' => t('Change my username and password.'),
76 77 78 79 80 81 82 83 84 85 86 87 88 89
  );
  $form['admin_account']['setup_account'] = array(
    '#type' => 'container',
    '#parents' => array('admin_account'),
    '#states' => array(
      'invisible' => array(
        'input[name="override_account_informations"]' => array('checked' => FALSE),
      ),
    ),
  );

  // Make a "copy" of the original name and pass form fields.
  $form['admin_account']['setup_account']['account']['name'] = $form['admin_account']['account']['name'];
  $form['admin_account']['setup_account']['account']['pass'] = $form['admin_account']['account']['pass'];
90
  $form['admin_account']['setup_account']['account']['pass']['#value'] = array('pass1' => 'admin', 'pass2' => 'admin');
91 92 93 94 95 96 97

  // Use "admin" as the default username.
  $form['admin_account']['account']['name']['#access'] = FALSE;

  // Make the password "hidden".
  $form['admin_account']['account']['pass']['#type'] = 'hidden';
  $form['admin_account']['account']['mail']['#access'] = FALSE;
98

99
  // Add a custom validation that needs to be trigger before the original one,
100
  // where we can copy the site's mail as the admin account's mail.
101
  array_unshift($form['#validate'], 'commerce_kickstart_custom_setting');
102 103 104
}

/**
105 106
 * Validate callback; Populate the admin account mail, user and password with
 * custom values.
107
 */
108
function commerce_kickstart_custom_setting(&$form, &$form_state) {
109
  $form_state['values']['account']['mail'] = $form_state['values']['site_mail'];
110 111 112
  // Use our custom values only the corresponding checkbox is checked.
  if ($form_state['values']['override_account_informations'] == TRUE) {
    if ($form_state['input']['pass']['pass1'] == $form_state['input']['pass']['pass2']) {
113
      $form_state['values']['account']['name'] = $form_state['values']['name'];
114 115
      $form_state['values']['account']['pass'] = $form_state['input']['pass']['pass1'];
    }
116
    else {
117 118
      form_set_error('pass', st('The specified passwords do not match.'));
    }
119
  }
120
}
121

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/**
 * Implements hook_system_info_alter().
 *
 * Hides conflicting features (so demo store users don't see the "no demo store"
 * features, and the other way around).
 */
function commerce_kickstart_system_info_alter(&$info, $file, $type) {
  // Don't run during installation.
  if (variable_get('install_task') != 'done') {
    return;
  }

  $install_demo_store = variable_get('commerce_kickstart_demo_store', FALSE);
  if ($install_demo_store) {
    $hide_modules = array(
      'commerce_kickstart_lite_product',
    );
  }
  else {
    $hide_modules = array(
      'commerce_kickstart_product',
    );
  }

  if ($type == 'module' && in_array($file->name, $hide_modules)) {
    $info['hidden'] = TRUE;
  }
}

151 152 153 154 155 156
/**
 * Implements hook_update_projects_alter().
 */
function commerce_kickstart_update_projects_alter(&$projects) {
  // Enable update status for the Commerce Kickstart profile.
  $modules = system_rebuild_module_data();
157 158 159 160
  // The module object is shared in the request, so we need to clone it here.
  $kickstart = clone $modules['commerce_kickstart'];
  $kickstart->info['hidden'] = FALSE;
  _update_process_info_list($projects, array('commerce_kickstart' => $kickstart), 'module', TRUE);
161 162 163 164 165
}

/**
 * Implements hook_update_status_alter().
 *
166 167 168 169 170 171
 * Disable reporting of projects that are in the distribution, but only
 * if they have not been updated manually.
 *
 * Projects with insecure / revoked / unsupported releases are only shown
 * after two days, which gives enough time to prepare a new Kickstart release
 * which the users can install and solve the problem.
172 173
 */
function commerce_kickstart_update_status_alter(&$projects) {
174
  $bad_statuses = array(
175 176
    UPDATE_NOT_SECURE,
    UPDATE_REVOKED,
177 178
    UPDATE_NOT_SUPPORTED,
  );
179

180 181 182 183
  $make_filepath = drupal_get_path('module', 'commerce_kickstart') . '/drupal-org.make';
  if (!file_exists($make_filepath)) {
    return;
  }
184

185 186
  $make_info = drupal_parse_info_file($make_filepath);
  foreach ($projects as $project_name => $project_info) {
187 188
    // Never unset the drupal project to avoid hitting an error with
    // _update_requirement_check(). See http://drupal.org/node/1875386.
189
    if ($project_name == 'drupal' || !isset($project_info['releases']) || !isset($project_info['recommended'])) {
190 191
      continue;
    }
192 193 194
    // Hide Kickstart projects, they have no update status of their own.
    if (strpos($project_name, 'commerce_kickstart_') !== FALSE) {
      unset($projects[$project_name]);
195
    }
196 197 198 199 200 201 202
    // Hide bad releases (insecure, revoked, unsupported) if they are younger
    // than two days (giving Kickstart time to prepare an update).
    elseif (isset($project_info['status']) && in_array($project_info['status'], $bad_statuses)) {
      $two_days_ago = strtotime('2 days ago');
      if ($project_info['releases'][$project_info['recommended']]['date'] < $two_days_ago) {
        unset($projects[$project_name]);
      }
203
    }
204 205 206 207 208 209 210
    // Hide projects shipped with Kickstart if they haven't been manually
    // updated.
    elseif (isset($make_info['projects'][$project_name])) {
      $version = $make_info['projects'][$project_name]['version'];
      if (strpos($version, 'dev') !== FALSE || (DRUPAL_CORE_COMPATIBILITY . '-' . $version == $project_info['info']['version'])) {
        unset($projects[$project_name]);
      }
211 212 213
    }
  }
}
214

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Disable the update for Commerce Kickstart.
 */
function commerce_kickstart_form_update_manager_update_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['projects']['#options']) && isset($form['projects']['#options']['commerce_kickstart'])) {
    if (count($form['projects']['#options']) > 1) {
      unset($form['projects']['#options']['commerce_kickstart']);
    }
    else {
      unset($form['projects']);
      // Hide Download button if there's no other (disabled) projects to update.
      if (!isset($form['disabled_projects'])) {
        $form['actions']['#access'] = FALSE;
      }
      $form['message']['#markup'] = t('All of your projects are up to date.');
    }
  }
}

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
/**
 * Provides a list of Crumbs plugins and their weights.
 */
function commerce_kickstart_crumbs_get_info() {
  $crumbs = array(
    'crumbs.home_title' => 0
  );

  foreach (module_implements('commerce_kickstart_crumb_info') as $module) {
    // The module-provided item might be just the name of the plugin, or it
    // might be an array in the form of $plugin_name => $weight.
    foreach (module_invoke($module, 'commerce_kickstart_crumb_info') as $crumb) {
      if (is_array($crumb)) {
        $crumbs += $crumb;
      }
      else {
        $crumbs[$crumb] = count($crumbs);
      }
    }
  }

  // Add the fallback wildcard.
  $crumbs['*'] = count($crumbs);

  asort($crumbs);

  return $crumbs;
}
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

/**
 * Rebuilds a feature using the same logic as features_modules_enabled().
 *
 * Called from the hook_enable() of every Kickstart feature.
 *
 * features_modules_enabled() runs too late, so when a feature's hook_enable()
 * or hook_install() runs, the feature hasn't been rebuild yet, no exported
 * structures exist in the system and can't be modified.
 * It also rebuilds all features at once, which makes it prone to timeouts.
 * This is why Kickstart disables features_modules_enabled() and rebuilds
 * each feature manually in its hook_enable() hook.
 */
function commerce_kickstart_rebuild_feature($module) {
  $feature = features_load_feature($module, TRUE);
  $items[$module] = array_keys($feature->info['features']);
  // Need to include any new files.
  features_include_defaults(NULL, TRUE);
  _features_restore('enable', $items);
  // Rebuild the list of features includes.
  features_include(TRUE);
  // Reorders components to match hook order and removes non-existant.
  $all_components = array_keys(features_get_components());
  foreach ($items as $module => $components) {
    $items[$module] = array_intersect($all_components, $components);
  }
  _features_restore('rebuild', $items);
}
292 293 294 295 296 297 298 299 300 301 302 303 304

/**
 * Implements hook_features_api_alter().
 *
 * Commerce Kickstart provides different Features that can be utilized
 * individually, which means there are conflicting field bases. This allows
 * the feature structure to exist, including customizations by users.
 */
function commerce_kickstart_features_api_alter(&$components) {
  if (isset($components['field_base'])) {
    $components['field_base']['duplicates'] = FEATURES_DUPLICATES_ALLOWED;
  }
}