interval.inc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Primary value passed to this field must be interval value itself (number of
  4. * periods).
  5. *
  6. * Pass the period as an argument, e.g.:
  7. *
  8. * @code
  9. * $arguments = array('period' => 'month');
  10. * $this->addFieldMapping('field_subscription_duration', 'num_months')
  11. * ->arguments($arguments);
  12. * @endcode
  13. */
  14. class MigrateIntervalFieldHandler extends MigrateFieldHandler {
  15. public function __construct() {
  16. $this->registerTypes(array('interval'));
  17. }
  18. public function prepare($entity, array $field_info, array $instance, array $values) {
  19. $arguments = array();
  20. if (isset($values['arguments'])) {
  21. $arguments = array_filter($values['arguments']);
  22. unset($values['arguments']);
  23. }
  24. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  25. // Setup the standard Field API array for saving.
  26. $delta = 0;
  27. foreach ($values as $value) {
  28. $return[$language][$delta] = array(
  29. 'interval' => $value,
  30. 'period' => $arguments['period'],
  31. );
  32. $delta++;
  33. }
  34. return isset($return) ? $return : NULL;
  35. }
  36. }