You are here

function mailchimp_lists_block_view in Mailchimp 7.2

Implements hook_block_view().

Provides a block for each available list for a given user

File

modules/mailchimp_lists/mailchimp_lists.module, line 880
Mailchimp lists module.

Code

function mailchimp_lists_block_view($delta = '') {
  $block = array();
  global $user;
  $list = mailchimp_lists_load($delta);
  $useful = FALSE;

  // @todo: figure out why were getting a block with the delta "freeform" here
  // and once we know, eliminate this 'if' clause.
  if (!empty($list)) {
    $useful = $list->settings['allow_anonymous'] && !empty($user->roles[DRUPAL_ANONYMOUS_RID]) || $list->settings['include_interest_groups'] || !$list->settings['required'];
  }
  foreach ($user->roles as $rid => $role) {
    $accessable = isset($list->settings['roles'][$rid]) && $list->settings['roles'][$rid];
    if ($accessable && $useful) {
      $block['subject'] = $list->settings['required'] ? t('@title Subscription Settings', array(
        '@title' => $list->label,
      )) : t('Subscribe to @title', array(
        '@title' => $list
          ->label(),
      ));
      $block['content'] = drupal_get_form('mailchimp_lists_user_subscribe_form_' . $list->name, array(
        $list,
      ), $user);
      break;
    }
  }
  return $block;
}