You are here

public function ContentImporter::importAll in Commerce Demo 8

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

Imports all content for the given entity type and bundle.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle.

1 call to ContentImporter::importAll()
ContentImporter::onInstall in src/ContentImporter.php
Reacts on the module being installed, imports all content.

File

src/ContentImporter.php, line 92

Class

ContentImporter
Defines the content importer.

Namespace

Drupal\commerce_demo

Code

public function importAll($entity_type_id, $bundle = '') {
  $filepath = $this
    ->buildFilepath($entity_type_id, $bundle);
  if (!is_readable($filepath)) {
    throw new \InvalidArgumentException(sprintf('The %s file could not be found/read.', $filepath));
  }
  $data = Yaml::decode(file_get_contents($filepath));
  foreach ($data as $uuid => $values) {
    $values['uuid'] = $uuid;
    $this
      ->importEntity($entity_type_id, $values);
  }
}