You are here

class MigrateYoutubeFieldHandler in YouTube Field 7

Extend MigrateFieldHandler for YouTube fields.

Hierarchy

Expanded class hierarchy of MigrateYoutubeFieldHandler

1 string reference to 'MigrateYoutubeFieldHandler'
youtube_migrate_api in ./youtube.migrate.inc
Implements hook_migrate_api().

File

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

View source
class MigrateYoutubeFieldHandler extends MigrateFieldHandler {

  /**
   * Declares the type(s) of fields used.
   */
  public function __construct() {
    $this
      ->registerTypes(array(
      'youtube',
    ));
  }

  /**
   * Arguments for a YouTube field migration.
   *
   * @param string $input
   *   The URL of the YouTube video. If a value is not supplied, this will be
   *   constructed from the $video_id.
   *
   * @return array
   *   An array of the defined variables in this scope.
   */
  public static function arguments($input = NULL) {
    return get_defined_vars();
  }

  /**
   * Implementation of MigrateFieldHandler::fields().
   *
   * @param string $type
   *   The field type.
   * @param array $instance
   *   Instance info for the field.
   * @param Migration|null $migration
   *   The migration context for the parent field. We can look at the mappings
   *   and determine which subfields are relevant.
   *
   * @return array
   *   Detail on the fields.
   */
  public function fields($type, array $instance, $migration = NULL) {
    return array(
      'input' => t('Subfield: The full YouTube video URL'),
    );
  }

  /**
   * Converts incoming data to the proper format for YouTube fields.
   *
   * @param object $entity
   *   The destination entity which will hold the field arrays.
   * @param array $field_info
   *   Metadata for the YouTube field being populated.
   * @param array $instance
   *   Metadata for this instance of the YouTube field being populated.
   * @param array $values
   *   Array of YouTube values to be fielded.
   *
   * @return array|null
   *   An array of YouTube fields.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateFieldHandler::getFieldLanguage function Determine the language of the field.
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type? 1
MigrateHandler::registerTypes protected function Register a list of types handled by this class
MigrateYoutubeFieldHandler::arguments public static function Arguments for a YouTube field migration.
MigrateYoutubeFieldHandler::fields public function Implementation of MigrateFieldHandler::fields().
MigrateYoutubeFieldHandler::prepare public function Converts incoming data to the proper format for YouTube fields.
MigrateYoutubeFieldHandler::__construct public function Declares the type(s) of fields used. Overrides MigrateHandler::__construct