You are here

public function ContentLoaderBase::loadContentBatch in YAML Content 8.2

Load a batch of content files.

Parameters

array $files: An array of file names for loading content from.

array $options: An array of configuration options to be used during this import.

Return value

array An associative array of loaded content items keyed by file name.

Overrides ContentLoaderInterface::loadContentBatch

File

src/ContentLoader/ContentLoaderBase.php, line 120

Class

ContentLoaderBase
A base ContentLoader implementation to be extended by new content loaders.

Namespace

Drupal\yaml_content\ContentLoader

Code

public function loadContentBatch(array $files, array $options = []) {

  // @todo Process options.
  // Dispatch the pre-import event.
  $pre_import_event = new PreImportEvent($this, $files);
  $this->dispatcher
    ->dispatch(YamlContentEvents::PRE_IMPORT, $pre_import_event);
  $loaded_content = [];
  foreach ($files as $file) {
    $content_data = $this
      ->parseContent($file);
    $loaded_content[$file] = $this
      ->loadContent($content_data);
  }

  // Dispatch the post-import event.
  $post_import_event = new PostImportEvent($this, $files, $loaded_content);
  $this->dispatcher
    ->dispatch(YamlContentEvents::POST_IMPORT, $post_import_event);

  // @todo Reset import options.
  return $loaded_content;
}