Field.php in Commerce Migrate 8.2
File
modules/ubercart/src/Plugin/migrate/source/uc7/Field.php
View source
<?php
namespace Drupal\commerce_migrate_ubercart\Plugin\migrate\source\uc7;
use Drupal\field\Plugin\migrate\source\d7\Field as D7Field;
class Field extends D7Field {
use ProductTypeTrait;
public function initializeIterator() {
$this->productTypes = $this
->getProductTypes();
$results = $this
->prepareQuery()
->execute();
$rows = [];
foreach ($results as $result) {
$field_name = $result['field_name'];
$query = $this
->select('field_config_instance', 'fci')
->fields('fci', [
'bundle',
])
->condition('fc.active', 1)
->condition('fc.storage_active', 1)
->condition('fc.deleted', 0)
->condition('fci.deleted', 0)
->condition('fci.entity_type', 'node');
$query
->join('field_config', 'fc', 'fci.field_id = fc.id');
$query
->condition('fci.field_name', $field_name);
$node_bundles = $query
->execute()
->fetchCol();
$product_node_count = 0;
foreach ($node_bundles as $bundle) {
if (in_array($bundle, $this->productTypes)) {
$product_node_count++;
}
}
$node_count = 0;
foreach ($node_bundles as $bundle) {
if ($bundle === 'node') {
$node_count++;
}
}
$result['commerce_product'] = 0;
if ($product_node_count > 0) {
if ($product_node_count == count($node_bundles)) {
$result['commerce_product'] = 1;
}
else {
$add_row = $result;
$add_row['commerce_product'] = 1;
$rows[] = $add_row;
}
}
$rows[] = $result;
}
return new \ArrayIterator($rows);
}
public function fields() {
$fields = parent::fields();
$fields['commerce_product'] = $this
->t('Product node flag');
return $fields;
}
public function getIds() {
$ids = parent::getIds();
return $ids + [
'commerce_product' => [
'type' => 'integer',
],
];
}
}
Classes
Name |
Description |
Field |
Ubercart 7 field source from database. |