You are here

public static function NodeUpdateMethod::getDestinationNode in GatherContent 8.4

Get Node object based on type of update.

Parameters

int $gc_id: ID of item in GatherContent.

string $node_update_method: Name of the node update method.

int $node_type_id: ID of the node type.

string $langcode: Language of translation if applicable.

Return value

\Drupal\node\NodeInterface Return loaded node.

1 call to NodeUpdateMethod::getDestinationNode()
ContentProcessor::createNode in src/Import/ContentProcess/ContentProcessor.php
Create a Drupal node filled with the properties of the GC item.

File

src/Import/NodeUpdateMethod.php, line 33

Class

NodeUpdateMethod
Constants specifying how to import/update nodes.

Namespace

Drupal\gathercontent\Import

Code

public static function getDestinationNode($gc_id, $node_update_method, $node_type_id, $langcode) {
  switch ($node_update_method) {
    case NodeUpdateMethod::UPDATE_IF_NOT_CHANGED:
      $result = \Drupal::entityQuery('node')
        ->condition('gc_id', $gc_id)
        ->sort('created', 'DESC')
        ->range(0, 1)
        ->execute();
      if ($result) {
        $node = Node::load(reset($result));
        $query_result = \Drupal::entityQuery('gathercontent_operation_item')
          ->condition('gc_id', $gc_id)
          ->sort('changed', 'DESC')
          ->range(0, 1)
          ->execute();
        $operation = OperationItem::load(reset($query_result));
        if ($node
          ->getChangedTime() === $operation
          ->getChangedTime()) {
          return $node;
        }
      }
      break;
    case NodeUpdateMethod::ALWAYS_UPDATE:
      $result = \Drupal::entityQuery('node')
        ->condition('gc_id', $gc_id)
        ->sort('created', 'DESC')
        ->range(0, 1)
        ->execute();
      if ($result) {
        return Node::load(reset($result));
      }
      break;
  }
  return Node::create([
    'type' => $node_type_id,
    'langcode' => $langcode,
  ]);
}