You are here

function addtocal_extract_event_info in Add to Cal 7

Return event information in an associative array based on a given entity.

Parameters

$entity_type:

$entity:

int $entity_id:

$field_name:

$display:

Return value

array

4 calls to addtocal_extract_event_info()
addtocal_download_ics in ./addtocal.module
Outputs an ICS file containing event information for the selected entity. Called by hook_menu.
addtocal_field_formatter_view in ./addtocal.module
Implements hook_field_formatter_view().
addtocal_google_link in ./addtocal.module
Redirects to a Google Calendar event. Called by hook_menu().
addtocal_yahoo_link in ./addtocal.module
Redirects to a Yahoo Calendar event. Called by hook_menu().

File

./addtocal.module, line 420
addtocal.module General functions and hook implementations.

Code

function addtocal_extract_event_info($entity_type, $entity, $entity_id, $field_name, $display) {
  $dates = field_get_items($entity_type, $entity, $field_name);
  $start_date = $dates[0]['value'];
  if (array_key_exists('value2', $dates[0])) {
    $end_date = $dates[0]['value2'];
  }
  else {
    $end_date = $start_date;
  }
  $timezone = $dates[0]['timezone_db'];
  if (isset($display['settings']['location_field'])) {
    $location = addtocal_field_get_value($entity_type, $entity, $display['settings']['location_field']);
  }
  if (isset($display['settings']['description_field'])) {
    $description = addtocal_field_get_value($entity_type, $entity, $display['settings']['description_field']);
    if (strlen($description) > 1024) {
      $description = truncate_utf8($description, 1024, TRUE, TRUE);
    }
  }
  $uri = entity_uri($entity_type, $entity);
  $url = $uri['path'];
  $info = array(
    'title' => check_plain($entity->title),
    'start' => $start_date,
    'end' => $end_date,
    'timezone' => $timezone,
    'location' => isset($location) ? $location : NULL,
    'description' => isset($description) ? $description : NULL,
    'entity_id' => $entity_id,
    'entity_type' => $entity_type,
    'url' => $url,
  );

  // Allow other modules to directly alter the addtocal info.
  drupal_alter('addtocal_extract_event_info', $info, $entity_type, $entity);
  return $info;
}