Vocabulary.php in Commerce Migrate 8.2
File
modules/commerce/src/Plugin/migrate/source/commerce1/Vocabulary.php
View source
<?php
namespace Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1;
use Drupal\migrate\Row;
use Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary as CoreVocabulary;
class Vocabulary extends CoreVocabulary {
public function fields() {
return parent::fields() + [
'attribute' => $this
->t('Attribute flag'),
];
}
public function prepareRow(Row $row) {
$query = $this
->select('field_config_instance', 'fci')
->fields('fci')
->fields('fc', [
'type',
])
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fci.deleted', 0)
->condition('fci.entity_type', 'commerce_product')
->condition('fc.type', 'taxonomy_term_reference');
$query
->join('field_config', 'fc', 'fci.field_id = fc.id');
$query
->addField('fc', 'data', 'fc_data');
$results = $query
->execute()
->fetchAll();
$row
->setSourceProperty('attribute', FALSE);
foreach ($results as $key => $value) {
$results[$key]['data'] = unserialize($value['data']);
$results[$key]['fc_data'] = unserialize($value['fc_data']);
$allowed_values = $results[$key]['fc_data']['settings']['allowed_values'][0]['vocabulary'];
if ($allowed_values === $row
->getSourceProperty('machine_name') && $results[$key]['data']['widget']['type'] == 'options_select') {
$row
->setSourceProperty('attribute', TRUE);
break;
}
}
return parent::prepareRow($row);
}
}
Classes
Name |
Description |
Vocabulary |
Drupal 7 vocabularies source from database. |