You are here

function PMPAPIDrupalPull::modifyDate in Public Media Platform API Integration 7

Turn PMP date data into acceptable Drupal date field data

Parameters

$values: The values (values, format, timezone) that constitute the local field

$local_field_info array: Info about the local field being mapped to.

$entity: The entity to which the doc is being mapped.

$entity_type string: The type (node, file, etc.) of the entity

$bundle_name string: The bundle (article, audio, etc.) of the entity

1 call to PMPAPIDrupalPull::modifyDate()
PMPAPIDrupalPull::alterMappedValues in pmpapi_pull/classes/PMPAPIDrupalPull.php
Alter values just prior to mapping.

File

pmpapi_pull/classes/PMPAPIDrupalPull.php, line 397
Contains PMPAPIDrupalPull.

Class

PMPAPIDrupalPull
Turns PMP hypermedia docs in Drupal entities.

Code

function modifyDate(&$values, $local_field_info, $entity, $entity_type, $bundle_name) {
  $instance_info = field_info_instance($entity_type, $local_field_info['field_name'], $bundle_name);
  $input_format = $instance_info['widget']['settings']['input_format'];
  $tz_handling = $local_field_info['settings']['tz_handling'];

  // Overly complex logic is intentional, as to spell out all five
  // timezone handler options
  switch ($tz_handling) {
    case 'site':
    case 'user':
    case 'utc':
    case 'none':
      $tz = 'UTC';
      break;
    case 'date':
      $tz = 'UTC';
      $values['timezone'] = 'UTC';
      break;
  }
  $ts = strtotime($values['value']);
  switch ($local_field_info['type']) {

    // Public field type = 'Date' (yes, this is confusing)
    // See https://www.drupal.org/node/1455576
    case 'datetime':
      $values['value'] = format_date($ts, 'custom', 'Y-m-d H:i:s', $tz);
      break;

    // Public field type = 'Date (ISO format)'
    case 'date':
      $values['value'] = format_date($ts, 'custom', 'Y-m-d\\TH:i:s', $tz);
      break;
    case 'datestamp':
      $values['value'] = $ts;
      break;
  }
}