You are here

class MigrateTextFieldHandler in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/destinations/fields.inc \MigrateTextFieldHandler

Hierarchy

Expanded class hierarchy of MigrateTextFieldHandler

1 string reference to 'MigrateTextFieldHandler'
migrate_migrate_api in ./migrate.module

File

plugins/destinations/fields.inc, line 160
Support for processing CCK fields

View source
class MigrateTextFieldHandler extends MigrateFieldHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'text',
      'text_long',
      'text_with_summary',
    ));
  }

  /**
   * Build an arguments array for text fields.
   *
   * @param string $summary
   *  N/A in Drupal 6.
   * @param string $format
   *  Text format to apply.
   * @param string $language
   *  N/A in Drupal 6.
   * @return array
   */
  static function arguments($summary = NULL, $format = NULL, $language = NULL) {
    $arguments = array();
    if (!is_null($summary)) {
      $arguments['summary'] = $summary;
    }
    if (!is_null($format)) {
      $arguments['format'] = $format;
    }
    if (!is_null($language)) {
      $arguments['language'] = $language;
    }
    return $arguments;
  }
  public function prepare($entity, array $instance, array $values) {
    if (isset($values['arguments'])) {
      $arguments = $values['arguments'];
      unset($values['arguments']);
    }
    else {
      $arguments = array();
    }
    $migration = Migration::currentMigration();
    $destination = $migration
      ->getDestination();
    $max_length = isset($instance['max_length']) ? $instance['max_length'] : 0;

    // Setup the standard Field API array for saving.
    $delta = 0;
    foreach ($values as $value) {
      $item = array();
      if (isset($arguments['format'])) {
        if (is_array($arguments['format'])) {
          $format = $arguments['format'][$delta];
        }
        else {
          $format = $arguments['format'];
        }
      }
      else {
        $format = $destination
          ->getTextFormat();
      }
      $item['format'] = $item['value_format'] = $format;

      // Make sure the value will fit
      if ($max_length) {
        $item['value'] = drupal_substr($value, 0, $max_length);
        if (!empty($arguments['track_overflow'])) {
          $value_length = drupal_strlen($value);
          if ($value_length > $max_length) {
            $migration
              ->saveMessage(t('Value for field !field exceeds max length of !max_length, actual length is !length', array(
              '!field' => $instance['field_name'],
              '!max_length' => $max_length,
              '!length' => $value_length,
            )), Migration::MESSAGE_INFORMATIONAL);
          }
        }
      }
      else {
        $item['value'] = $value;
      }
      $return[$delta] = $item;
      $delta++;
    }
    return isset($return) ? $return : NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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?
MigrateHandler::registerTypes protected function Register a list of types handled by this class
MigrateTextFieldHandler::arguments static function Build an arguments array for text fields.
MigrateTextFieldHandler::prepare public function
MigrateTextFieldHandler::__construct public function Overrides MigrateHandler::__construct