function block_form_user_profile_form_alter

Implements hook_form_FORM_ID_alter() for user_profile_form().

File

drupal/core/modules/block/block.module, line 598
Controls the visual building blocks a page is constructed with.

Code

function block_form_user_profile_form_alter(&$form, &$form_state) {
  $account = $form_state['controller']
    ->getEntity($form_state);
  $rids = array_keys($account->roles);
  $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(
    ':rids' => $rids,
  ));
  $account_data = drupal_container()
    ->get('user.data')
    ->get('block', $account
    ->id(), 'block');
  $blocks = array();
  foreach ($result as $block) {
    $data = module_invoke($block->module, 'block_info');
    if ($data[$block->delta]['info']) {
      $blocks[$block->module][$block->delta] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($data[$block->delta]['info']),
        '#default_value' => isset($account_data[$block->module][$block->delta]) ? $account_data[$block->module][$block->delta] : $block->custom == 1,
      );
    }
  }

  // Only display the form element if there are any personalizable blocks.
  if ($blocks) {
    $form['block'] = array(
      '#type' => 'details',
      '#title' => t('Personalize blocks'),
      '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'),
      '#weight' => 3,
      '#collapsible' => TRUE,
      '#tree' => TRUE,
    );
    $form['block'] += $blocks;
  }
}