You are here

function birthdays_field_formatter_view in Birthdays 7

Implements hook_field_formatter_view().

File

./birthdays.module, line 480
The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an email on their birthday automatically, and the administrator can receive daily reminders of…

Code

function birthdays_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $bp = base_path();
  foreach ($items as $delta => $item) {
    $birthday = BirthdaysBirthday::fromArray($item);
    if ($birthday
      ->isEmpty()) {
      continue;
    }
    $starsign = $birthday
      ->getStarsign();
    switch ($display['type']) {
      case 'birthdays_plaintext':
        $element[$delta] = array(
          '#markup' => check_plain($birthday
            ->toString($display['settings']['dateformat'], $display['settings']['dateformat_noyear'])),
        );
        break;
      case 'birthdays_starsign':
        if (!$birthday
          ->isEmpty()) {
          $element[$delta] = array(
            '#theme' => 'image',
            '#path' => $bp . drupal_get_path('module', 'birthdays') . '/starsigns/' . $starsign . '.gif',
            '#height' => '35',
            '#width' => '35',
            '#alt' => t(ucfirst($starsign)),
            '#title' => t(ucfirst($starsign)),
          );
          if ($display['settings']['starsign_with_yahoo_link']) {
            $image = $element[$delta];
            $link = array(
              '#theme' => 'link',
              '#text' => drupal_render($image),
              '#path' => 'http://shine.yahoo.com/horoscope/' . $starsign,
              '#options' => array(
                'attributes' => array(),
                'html' => TRUE,
              ),
            );
            $element[$delta] = $link;
          }
        }
        break;
      case 'birthdays_age':
        if ($birthday
          ->getYear()) {
          $element[$delta] = array(
            '#markup' => check_plain($birthday
              ->getCurrentAge()),
          );
        }
        break;
      case 'birthdays_age_upcoming':
        if ($birthday
          ->getYear()) {
          $element[$delta] = array(
            '#markup' => check_plain($birthday
              ->getCurrentAge() + 1),
          );
        }
        break;
    }
  }
  return $element;
}