You are here

public function ManageExport::importFrom in Content Export YAML 8

Import all entity

4 calls to ManageExport::importFrom()
ManageExport::importAll in src/ManageExport.php
ManageExport::importBlockAll in src/ManageExport.php
ManageExport::importNodeAll in src/ManageExport.php
ManageExport::importTermAll in src/ManageExport.php

File

src/ManageExport.php, line 114

Class

ManageExport

Namespace

Drupal\content_export_yaml

Code

public function importFrom($entity, $bundle, array $range, $options) {
  $path = isset($options['path']) ? $options['path'] : null;
  $yamls = $this->func
    ->load_entity_config_list_with_path($entity, $bundle, $range, $path);
  $parsed = new Parser();
  $status_list = [];
  foreach ($yamls as $content) {
    $object = $parsed
      ->parse($content, SymfonyYaml::PARSE_OBJECT);
    if (is_object($object)) {
      $status = $this->func
        ->savingEntity($object, $entity);
      if ($status != 1 || $status != 2) {
        \Drupal::messenger()
          ->addMessage(t('Failed to save item'), 'error');
      }
      $status_list[] = [
        'status' => $status,
        'label' => $object
          ->label(),
        'file_name' => $object
          ->id(),
      ];
    }
    else {
      \Drupal::messenger()
        ->addMessage(t('Failed to convert yaml to object'), 'error');
    }
  }
  return $status_list;
}