You are here

public function MigrateYoutubeFieldHandler::prepare in YouTube Field 7

Converts incoming data to the proper format for YouTube fields.

Parameters

object $entity: The destination entity which will hold the field arrays.

array $field_info: Metadata for the YouTube field being populated.

array $instance: Metadata for this instance of the YouTube field being populated.

array $values: Array of YouTube values to be fielded.

Return value

array|null An array of YouTube fields.

File

./youtube.migrate.inc, line 80
YouTube Field support for use with the migrate module.

Class

MigrateYoutubeFieldHandler
Extend MigrateFieldHandler for YouTube fields.

Code

public function prepare($entity, array $field_info, array $instance, array $values) {
  if (isset($values['arguments'])) {
    $arguments = $values['arguments'];
    unset($values['arguments']);
  }
  else {
    $arguments = array();
  }
  $language = $this
    ->getFieldLanguage($entity, $field_info, $arguments);
  $values = array_filter($values);
  foreach ($values as $delta => $value) {
    $item = array();
    $video_id = youtube_get_video_id($value);
    if (!empty($video_id)) {
      $item['input'] = $value;
      $item['video_id'] = $video_id;
    }
    $return[$language][$delta] = $item;
  }
  return isset($return) ? $return : NULL;
}