You are here

function embonus_emfield_field_extra in Embedded Media Field 6.2

Implementation of hook_emfield_field_extra().

File

contrib/embonus/embonus.module, line 76

Code

function embonus_emfield_field_extra($op, &$node, $field, &$items, $teaser, $page, $module) {
  switch ($op) {
    case 'validate':

      // Ensure end > start if present.
      foreach ($items as $delta => $item) {
        $start = embonus_convert_to_seconds($items[$delta]['embonus']['start_end_times']['start_time']);
        $end = embonus_convert_to_seconds($items[$delta]['embonus']['start_end_times']['end_time']);
        if ($start < 0) {
          $error_field = $field['field_name'] . '][' . $delta . '][embonus][start_end_times][start_time';
          form_set_error($error_field, t('The start time for this media cannot be less than 0 seconds.'));
        }
        if ($end < 0) {
          $error_field = $field['field_name'] . '][' . $delta . '][embonus][start_end_times][end_time';
          form_set_error($error_field, t('The end time for this media cannot be less than 0 seconds.'));
        }
        if ($end && $end <= $start) {
          $error_field = $field['field_name'] . '][' . $delta . '][embonus][start_end_times][end_time';
          form_set_error($error_field, t('The end time for this media, if present, must be greater than the start time.'));
        }
      }
      break;
    case 'presave':
      if ($field['widget']['collect_start_end_times']) {
        foreach ($items as $delta => $item) {
          $items[$delta]['start_time'] = embonus_convert_to_seconds($items[$delta]['embonus']['start_end_times']['start_time']);
          $items[$delta]['end_time'] = embonus_convert_to_seconds($items[$delta]['embonus']['start_end_times']['end_time']);
        }
      }
      break;
  }
}