You are here

public function SyncCoreBatchCollection::add in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/SyncCoreBatchCollection.php \Drupal\cms_content_sync\SyncCoreBatchCollection::add()
  2. 2.0.x src/SyncCoreBatchCollection.php \Drupal\cms_content_sync\SyncCoreBatchCollection::add()

Add or overwrite an item if one exists with the given ID.

Parameters

array $item:

string $type:

Return value

$this

File

src/SyncCoreBatchCollection.php, line 45

Class

SyncCoreBatchCollection
Class SyncCoreBatchCollection.

Namespace

Drupal\cms_content_sync

Code

public function add($item, $type) {

  // If an item with that ID already exists, we overwrite it.
  foreach ($this->operations as &$operation) {
    if ($operation['type'] !== $type) {
      continue;
    }
    if ($operation['item']['id'] !== $item['id']) {
      continue;
    }
    $operation['item'] = $item;
    return $this;
  }
  $this->operations[] = [
    'type' => $type,
    'item' => $item,
  ];
  return $this;
}