You are here

public function OgVocabMigrate::prepareRow in OG Vocabulary 7

Default implementation of prepareRow(). This method is called from the source plugin upon first pulling the raw data from the source.

Parameters

$row: Object containing raw source data.

Return value

bool TRUE to process this row, FALSE to have the source skip it.

Overrides Migration::prepareRow

File

includes/migrate/og_vocab.migrate.inc, line 65
Migrate plugin to populate the OG vocabulary field by the term references.

Class

OgVocabMigrate
@file Migrate plugin to populate the OG vocabulary field by the term references.

Code

public function prepareRow($row) {
  if (empty($this->fieldNames)) {
    return;
  }
  $field_names = $this->fieldNames;

  // We don't have the fields in the $row, so we load the entity to get
  // them.
  $wrapper = entity_metadata_wrapper('node', $row->nid);
  $tids = array();
  foreach ($field_names as $field_name) {
    $field = field_info_field($field_name);
    $vocabulary = taxonomy_vocabulary_machine_name_load($field['settings']['allowed_values'][0]['vocabulary']);
    $this
      ->addOgVocab($vocabulary->vid, $field_name);
    if ($values = $wrapper->{$field_name}
      ->value(array(
      'identifier' => TRUE,
    ))) {
      $values = is_array($values) ? $values : array(
        $values,
      );
      $tids = array_merge($tids, $values);
    }
  }
  $row->{OG_VOCAB_FIELD} = $tids;
  parent::prepareRow($row);
}