setSourceProperty example

'translation' => $this->t('Translation of either the title or explanation.'),
    ];
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    // For ease of reading the migration use 'language' as the property name for     // the language.     $language = $row->getSourceProperty('ltlanguage');
    $row->setSourceProperty('language', $language);
    return parent::prepareRow($row);
  }

  /** * {@inheritdoc} */
  public function getIds() {
    $ids['vid']['type'] = 'integer';
    $ids['language']['type'] = 'string';
    $ids['language']['alias'] = 'lt';
    return $ids;
  }
      $current_options = preg_split("/[\r\n]+/", $row->getSourceProperty('options'));
      // Select the list values from the profile_values table to ensure we get       // them all since they can get out of sync with profile_fields.       $options = $this->select($this->valueTable, 'pv')
        ->distinct()
        ->fields('pv', ['value'])
        ->condition('fid', $row->getSourceProperty('fid'))
        ->execute()
        ->fetchCol();
      $options = array_merge($current_options$options);
      // array_combine() takes care of any duplicates options.       $row->setSourceProperty('options', array_combine($options$options));
    }

    if ($row->getSourceProperty('type') == 'checkbox') {
      // D6 profile checkboxes values are always 0 or 1 (with no labels), so we       // need to create two label-less options that will get 0 and 1 for their       // keys.       $row->setSourceProperty('options', [NULL, NULL]);
    }

    return parent::prepareRow($row);
  }

  
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    if (!parent::prepareRow($row)) {
      return FALSE;
    }

    // Override language with ltlanguage.     $language = $row->getSourceProperty('ltlanguage');
    $row->setSourceProperty('language', $language);

    // Set the i18n string table for use in I18nQueryTrait.     $this->i18nStringTable = 'i18n_string';

    // Save the translation for the property already in the row.     $property_in_row = $row->getSourceProperty('property');

    // Get the translation for the property not already in the row and save it     // in the row.     $property_not_in_row = ($property_in_row == 'name') ? 'description' : 'name';
    return $this->getPropertyNotInRowTranslation($row$property_not_in_row, 'tid', $this->idMap);
  }

  protected function doCount() {
    return $this->initializeIterator()->count();
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $exists = $this->moduleExists($row->getSourceProperty('module'));
    $row->setSourceProperty('module_exists', $exists);
    return parent::prepareRow($row);
  }

}
$results = $this->select('image_effects', 'ie')
      ->fields('ie')
      ->condition('isid', $row->getSourceProperty('isid'))
      ->execute();

    foreach ($results as $key => $result) {
      $result['data'] = unserialize($result['data']);
      $effects[$key] = $result;
    }

    $row->setSourceProperty('effects', $effects);
    return parent::prepareRow($row);
  }

}
// The instance widget_type helps determine what D8 field type we'll use.     // Identify the distinct widget_types being used in D6.     $widget_types = $this->select('content_node_field_instance', 'cnfi')
      ->fields('cnfi', ['widget_type'])
      ->condition('field_name', $row->getSourceProperty('field_name'))
      ->distinct()
      ->orderBy('widget_type')
      ->execute()
      ->fetchCol();
    // Arbitrarily use the first widget_type - if there are multiples, let the     // migrator know.     $row->setSourceProperty('widget_type', $widget_types[0]);
    if (count($widget_types) > 1) {
      $this->migration->getIdMap()->saveMessage(
        ['field_name' => $row->getSourceProperty('field_name')],
        $this->t('Widget types @types are used in Drupal 6 field instances: widget type @selected_type applied to the Drupal 8 base field', [
          '@types' => implode(', ', $widget_types),
          '@selected_type' => $widget_types[0],
        ])
      );
    }

    // Unserialize data.


  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    if (!parent::prepareRow($row)) {
      return FALSE;
    }

    // Put the language on the row as 'language'.     $row->setSourceProperty('language', $row->getSourceProperty('lt_language'));

    // Save the translation for this property.     $property_in_row = $row->getSourceProperty('property');

    // Set the i18n string table for use in I18nQueryTrait.     $this->i18nStringTable = 'i18n_string';
    // Get the translation for the property not already in the row and save it     // in the row.     $property_not_in_row = ($property_in_row == 'title') ? 'description' : 'title';
    return $this->getPropertyNotInRowTranslation($row$property_not_in_row, 'mlid', $this->idMap);
  }

  
->fields('pv', ['fid', 'value']);
    $query->leftJoin('profile_fields', 'pf', '[pf].[fid] = [pv].[fid]');
    $query->fields('pf', ['name', 'type']);
    $query->condition('uid', $row->getSourceProperty('uid'));
    $results = $query->execute();

    foreach ($results as $profile_value) {
      // Check special case for date. We need to unserialize.       if ($profile_value['type'] == 'date') {
        $date = unserialize($profile_value['value']);
        $date = date('Y-m-d', mktime(0, 0, 0, $date['month']$date['day']$date['year']));
        $row->setSourceProperty($profile_value['name']['value' => $date]);
      }
      elseif ($profile_value['type'] == 'list') {
        // Explode by newline and comma.         $row->setSourceProperty($profile_value['name']preg_split("/[\r\n,]+/", $profile_value['value']));
      }
      else {
        $row->setSourceProperty($profile_value['name'][$profile_value['value']]);
      }
    }

    return parent::prepareRow($row);
  }
$this->expectException(\Exception::class);
    new Row($invalid_values$this->testSourceIds);
  }

  /** * Tests source immutability after freeze. */
  public function testSourceFreeze() {
    $row = new Row($this->testValues, $this->testSourceIds);
    $row->rehash();
    $this->assertSame($this->testHash, $row->getHash(), 'Correct hash.');
    $row->setSourceProperty('title', 'new title');
    $row->rehash();
    $this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.');
    $row->freezeSource();
    $this->expectException(\Exception::class);
    $row->setSourceProperty('title', 'new title');
  }

  /** * Tests setting on a frozen row. */
  public function testSetFrozenRow() {
    
return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    if (!parent::prepareRow($row)) {
      return FALSE;
    }
    $row->setSourceProperty('language', $row->getSourceProperty('td_language'));
  }

  /** * {@inheritdoc} */
  public function fields() {
    $fields = [
      'language' => $this->t('Language for this term.'),
      'name_translated' => $this->t('Term name translation.'),
      'description_translated' => $this->t('Term description translation.'),
    ];
    
    // 0 - No multilingual options     // 1 - Localizable terms. Run through the localization system.     // 2 - Predefined language for a vocabulary and its terms.     // 3 - Per-language terms, translatable (referencing terms with different     // languages) but not localizable.     $i18ntaxonomy_vocabulary = $this->variableGet('i18ntaxonomy_vocabulary', []);
    $vid = $row->getSourceProperty('vid');
    $state = 0;
    if (array_key_exists($vid$i18ntaxonomy_vocabulary)) {
      $state = $i18ntaxonomy_vocabulary[$vid];
    }
    $row->setSourceProperty('state', $state);
    return parent::prepareRow($row);
  }

  /** * {@inheritdoc} */
  public function getIds() {
    $ids['vid']['type'] = 'integer';
    return $ids;
  }

}
if (!$object_id) {
      throw new MigrateException('No objectid found.');
    }

    // If this row has been migrated it is a duplicate so skip it.     if ($id_map->lookupDestinationIds([$object_id_name => $object_id, 'language' => $language])) {
      return FALSE;
    }

    // Save the translation for the property already in the row.     $property_in_row = $row->getSourceProperty('property');
    $row->setSourceProperty($property_in_row . '_translated', $row->getSourceProperty('translation'));

    // Get the translation, if one exists, for the property not already in the     // row.     $query = $this->select($this->i18nStringTable, 'i18n')
      ->fields('i18n', ['lid'])
      ->condition('i18n.property', $property_not_in_row)
      ->condition('i18n.objectid', $object_id);
    $query->leftJoin('locales_target', 'lt', '[i18n].[lid] = [lt].[lid]');
    $query->condition('lt.language', $language);
    $query->addField('lt', 'translation');
    $results = $query->execute()->fetchAssoc();
    
$fields = [
      'ml_language' => $this->t('Menu link ID of the source language menu link.'),
      'skip_source_translation' => $this->t('Menu link description translation.'),
    ];
    return parent::fields() + $fields;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $row->setSourceProperty('skip_source_translation', TRUE);
    // Get the mlid for the source menu_link.     $source_mlid = $this->select('menu_links', 'ml')
      ->fields('ml', ['mlid'])
      ->condition('i18n_tsid', $row->getSourceProperty('i18n_tsid'))
      ->orderBy('mlid')
      ->range(0, 1)
      ->execute()
      ->fetchField();
    if ($source_mlid == $row->getSourceProperty('mlid')) {
      $row->setSourceProperty('skip_source_translation', FALSE);
    }
    
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    $uid = $row->getSourceProperty('uid');

    $roles = $this->select('users_roles', 'ur')
      ->fields('ur', ['rid'])
      ->condition('ur.uid', $uid)
      ->execute()
      ->fetchCol();
    $row->setSourceProperty('roles', $roles);

    $row->setSourceProperty('data', unserialize($row->getSourceProperty('data') ?? ''));

    // If this entity was translated using Entity Translation, we need to get     // its source language to get the field values in the right language.     // The translations will be migrated by the d7_user_entity_translation     // migration.     $entity_translatable = $this->isEntityTranslatable('user');
    $source_language = $this->getEntityTranslationSourceLanguage('user', $uid);
    $language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
    $row->setSourceProperty('entity_language', $language);

    

  public function prepareRow(Row $row) {
    $tid = $row->getSourceProperty('entity_id');
    $vocabulary = $row->getSourceProperty('machine_name');
    $language = $row->getSourceProperty('language');

    // Get Field API field values.     foreach ($this->getFields('taxonomy_term', $vocabulary) as $field_name => $field) {
      // Ensure we're using the right language if the entity is translatable.       $field_language = $field['translatable'] ? $language : NULL;
      $row->setSourceProperty($field_name$this->getFieldValues('taxonomy_term', $field_name$tid, NULL, $field_language));
    }

    // If the term name or term description were replaced by real fields using     // the Drupal 7 Title module, use the fields value instead of the term name     // or term description.     if ($this->moduleExists('title')) {
      $name_field = $row->getSourceProperty('name_field');
      if (isset($name_field[0]['value'])) {
        $row->setSourceProperty('name', $name_field[0]['value']);
      }
      $description_field = $row->getSourceProperty('description_field');
      
Home | Imprint | This part of the site doesn't use cookies.