You are here

public function FarmQuickEntity::prepareQuickEntityRow in farmOS 2.x

Prepare reference to the 1.x quick form that created this entity.

Parameters

\Drupal\migrate\Row $row: The row object.

string $entity_type: The 2.x entity type.

2 calls to FarmQuickEntity::prepareQuickEntityRow()
FarmAsset::prepareRow in modules/core/migrate/src/Plugin/migrate/source/d7/FarmAsset.php
Adds additional data to the row.
FarmLog::prepareRow in modules/core/migrate/src/Plugin/migrate/source/d7/FarmLog.php
Adds additional data to the row.

File

modules/core/migrate/src/Traits/FarmQuickEntity.php, line 20

Class

FarmQuickEntity
Asset source from database.

Namespace

Drupal\farm_migrate\Traits

Code

public function prepareQuickEntityRow(Row $row, string $entity_type) {
  $quick = [];

  // Load the entity ID.
  $id = $row
    ->getSourceProperty('id');

  // Translate the 2.x entity type names to 1.x.
  $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];
  }

  // Check to see if the 1.x farm_quick module is enabled.
  $query = $this
    ->select('system', 's');
  $query
    ->condition('s.name', 'farm_quick');
  $query
    ->condition('s.status', 1);
  $enabled = $query
    ->countQuery()
    ->execute()
    ->fetchField();

  // If the farm_quick module is enabled, look up quick form(s) that are
  // linked to this entity.
  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;
        }
      }
    }
  }

  // Translate the 1.x quick form IDs to 2.x.
  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];
      }
    }
  }

  // Set the "quick" source property.
  $row
    ->setSourceProperty('quick', $quick);
}