AnimalAsset.php in farmOS 2.x
File
modules/core/migrate/src/Plugin/migrate/source/d7/AnimalAsset.php
View source
<?php
namespace Drupal\farm_migrate\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
class AnimalAsset extends FarmAsset {
public function prepareRow(Row $row) {
$id = $row
->getSourceProperty('id');
$animal_tag_values = $this
->getFieldValues('farm_asset', 'field_farm_animal_tag', $id);
$field_collection_item_ids = [];
foreach ($animal_tag_values as $animal_tag_value) {
if (!empty($animal_tag_value['value'])) {
$field_collection_item_ids[] = $animal_tag_value['value'];
}
}
$animal_tags = [];
foreach ($field_collection_item_ids as $item_id) {
$query = $this
->select('field_collection_item', 'fci')
->condition('fci.item_id', $item_id)
->condition('fci.field_name', 'field_farm_animal_tag');
$query
->leftJoin('field_data_field_farm_animal_tag_id', 'fdffati', 'fdffati.entity_id = fci.item_id AND fdffati.deleted = 0');
$query
->addField('fdffati', 'field_farm_animal_tag_id_value', 'id');
$query
->leftJoin('field_data_field_farm_animal_tag_type', 'fdffatt', 'fdffatt.entity_id = fci.item_id AND fdffatt.deleted = 0');
$query
->addField('fdffatt', 'field_farm_animal_tag_type_value', 'type');
$query
->leftJoin('field_data_field_farm_animal_tag_location', 'fdffatl', 'fdffatl.entity_id = fci.item_id AND fdffatl.deleted = 0');
$query
->addField('fdffatl', 'field_farm_animal_tag_location_value', 'location');
$animal_tags[] = $query
->execute()
->fetchAssoc();
}
$row
->setSourceProperty('animal_tags', $animal_tags);
return parent::prepareRow($row);
}
}