You are here

public function ContentLoader::parseContent in YAML Content 8

Parse the given yaml content file into an array.

Parameters

string $content_file: A file name for the content file to be loaded. The file is assumed to be located within a directory set by `setPath()`.

Return value

array The parsed content array from the file.

Overrides ContentLoaderInterface::parseContent

1 call to ContentLoader::parseContent()
ContentLoader::loadContent in src/ContentLoader/ContentLoader.php
Load all demo content for this loader.

File

src/ContentLoader/ContentLoader.php, line 283

Class

ContentLoader
ContentLoader class for parsing and importing YAML content.

Namespace

Drupal\yaml_content\ContentLoader

Code

public function parseContent($content_file) {
  $file = $this->path . '/content/' . $content_file;

  // @todo Handle missing files gracefully.
  $this->parsedContent = $this
    ->getParser()
    ->parse(file_get_contents($file));

  // Never leave this as null, even on a failed parsing process.
  // @todo Output a warning for empty content files or failed parsing.
  $this->parsedContent = isset($this->parsedContent) ? $this->parsedContent : [];

  // Dispatch the event notification.
  $content_parsed_event = new ContentParsedEvent($this, $this->contentFile, $this->parsedContent);
  $this
    ->getEventDispatcher()
    ->dispatch(YamlContentEvents::CONTENT_PARSED, $content_parsed_event);
  return $this->parsedContent;
}