You are here

protected function RevisionHandler::cleanUp in Feeds Paragraphs 8

Cleans up the entity and its paragraphs before saving the update.

Parameters

FieldConfigInterface[] $fields:

1 call to RevisionHandler::cleanUp()
RevisionHandler::handle in src/RevisionHandler.php

File

src/RevisionHandler.php, line 138

Class

RevisionHandler

Namespace

Drupal\feeds_para_mapper

Code

protected function cleanUp(array $fields) {

  // Load all attached entities for the target field:
  $loaded = array();
  foreach ($fields as $field_name => $field) {
    $loaded[$field_name] = $this->importer
      ->loadTarget($this->entity, $field);
  }

  // Check for any unused entities:
  foreach ($loaded as $field_name => $attached) {
    $used_entities = $fields[$field_name]
      ->get('target_info')->paragraphs;
    if (count($attached) > count($used_entities)) {
      $this
        ->removeUnused($used_entities, $attached, $fields[$field_name]);
    }
  }
}