Drupal Comment Field

I have been using this field in  a recent project needed to migrate data to it. No migrate handler existed so I created one. Probably the easiest five minutes I have used to program Drupal.

I have submitted it too https://www.drupal.org/node/2541912

But for those looking to migrate to this field use this code

 

<?php
class MigrateCommentFieldHandler extends MigrateFieldHandler {

  public function __construct() {
    $this->registerTypes(array('commentfield'));
  }

  public function prepare($entity, array $field_info, array $instance, array $values) {
    // Setup the Field API array for saving.
    $arguments = (isset($values['arguments'])) ? $values['arguments']: array();
    $language = $this->getFieldLanguage($entity, $field_info, $arguments);
    $delta = 0;
    foreach ($values as $value) {
      $return[$language][$delta]['comment'] = $value['comment'];
      $return[$language][$delta]['created'] = $value['created'];
      $return[$language][$delta]['uid']     = $value['uid'];
      $delta++;
    }
    return isset($return) ? $return : NULL;
  }
}
?>

 

Share with your friends
  • Twitter
  • Facebook
  • Tumblr
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Yahoo! Buzz
  • MySpace
  • email
  • RSS