You are here

protected function ContentExporter::processTerm in Commerce Demo 8

Same name and namespace in other branches
  1. 8.2 src/ContentExporter.php \Drupal\commerce_demo\ContentExporter::processTerm()

Processes the exported taxonomy term.

Parameters

array $export: The export array.

\Drupal\taxonomy\TermInterface $term: The taxonomy term.

Return value

array The processed export array.

1 call to ContentExporter::processTerm()
ContentExporter::export in src/ContentExporter.php
Exports the given entity.

File

src/ContentExporter.php, line 288

Class

ContentExporter
Defines the content exporter.

Namespace

Drupal\commerce_demo

Code

protected function processTerm(array $export, TermInterface $term) {

  /** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
  $term_storage = $this->entityTypeManager
    ->getStorage('taxonomy_term');
  if ($parents = $term_storage
    ->loadParents($term
    ->id())) {

    // The 'parent' doesn't export properly before Drupal 8.6.0. See #2543726.
    $parent_ids = array_keys($parents);
    $parent_ids = array_map(function ($parent_id) {
      return $this
        ->mapToUuid('taxonomy_term', $parent_id);
    }, $parent_ids);
    $export = [
      'parent' => $parent_ids,
    ] + $export;
  }
  return $export;
}