You are here

protected function LoadHelper::importFiles in YAML Content 8

Import content files using a Content Loader.

Parameters

array $files: An array of file descriptors as loaded by FileSystemInterface::scanDirectory() keyed by filename. Each of the listed files will be imported.

3 calls to LoadHelper::importFiles()
LoadHelper::importDirectory in src/Service/LoadHelper.php
Import specified yaml content file(s).
LoadHelper::importModule in src/Service/LoadHelper.php
Import specified yaml content file(s) from a designated module.
LoadHelper::importProfile in src/Service/LoadHelper.php
Import specified yaml content file(s) from a designated profile.

File

src/Service/LoadHelper.php, line 163

Class

LoadHelper
A helper class to support the content loading process.

Namespace

Drupal\yaml_content\Service

Code

protected function importFiles(array $files) {

  // @todo Verify files before loading for import.
  foreach ($files as $filename => $file) {

    // Log pre-import notices.
    \Drupal::messenger()
      ->addMessage($this
      ->t('Importing content: %file', [
      '%file' => $filename,
    ]));
    $this->logger
      ->notice('Importing content: %file', [
      '%file' => $filename,
    ]);
    $loaded = $this->loader
      ->loadContent($filename);

    // Log post-import summaries.
    \Drupal::messenger()
      ->addMessage($this
      ->t('Imported %count items from %file', [
      '%count' => count($loaded),
      '%file' => $filename,
    ]));
    $this->logger
      ->notice('Imported %count items from %file', [
      '%count' => count($loaded),
      '%file' => $filename,
    ]);
  }
}