FarmQuickEntity.php in farmOS 2.x
File
modules/core/migrate/src/Traits/FarmQuickEntity.php
View source
<?php
namespace Drupal\farm_migrate\Traits;
use Drupal\migrate\Row;
trait FarmQuickEntity {
public function prepareQuickEntityRow(Row $row, string $entity_type) {
$quick = [];
$id = $row
->getSourceProperty('id');
$old_entity_types = [
'asset' => 'farm_asset',
'log' => 'log',
'plan' => 'farm_plan',
];
if (array_key_exists($entity_type, $old_entity_types)) {
$entity_type = $old_entity_types[$entity_type];
}
$query = $this
->select('system', 's');
$query
->condition('s.name', 'farm_quick');
$query
->condition('s.status', 1);
$enabled = $query
->countQuery()
->execute()
->fetchField();
if (!empty($enabled)) {
$query = $this
->select('farm_quick_entity', 'fqe');
$query
->condition('entity_type', $entity_type);
$query
->condition('entity_id', $id);
$query
->addField('fqe', 'quick_form_id');
$result = $query
->execute()
->fetchCol();
if (!empty($result)) {
foreach ($result as $col) {
if (!empty($col)) {
$quick[] = $col;
}
}
}
}
if (!empty($quick)) {
$new_quick_form_ids = [];
foreach ($quick as $delta => $form_id) {
if (array_key_exists($form_id, $new_quick_form_ids)) {
$quick[$delta] = $new_quick_form_ids[$form_id];
}
}
}
$row
->setSourceProperty('quick', $quick);
}
}