You are here

public function ProcessedContentLoader::loadProcessor in YAML Content 8.2

Load the processor plugin for use on the import content.

Load the processor plugin and configure any relevant context available in the provided `$context` parameter.

@todo Handle PluginNotFoundException.

Parameters

string $processor_id: The machine name identifier of the processor to be loaded.

array $context: Contextual data to configure the loaded processor plugin.

Return value

\Drupal\yaml_content\ImportProcessorInterface The loaded import processor object.

Throws

\Exception

2 calls to ProcessedContentLoader::loadProcessor()
ProcessedContentLoader::postprocessData in src/ContentLoader/ProcessedContentLoader.php
Evaluate the current import data array and run any preprocessing needed.
ProcessedContentLoader::preprocessData in src/ContentLoader/ProcessedContentLoader.php
Evaluate the current import data array and run any preprocessing needed.

File

src/ContentLoader/ProcessedContentLoader.php, line 132

Class

ProcessedContentLoader
A ContentLoader supporting processing of content through plugins.

Namespace

Drupal\yaml_content\ContentLoader

Code

public function loadProcessor($processor_id, array &$context) {
  $processor_definition = $this->processorPluginManager
    ->getDefinition($processor_id);

  // @todo Implement exception class for invalid processors.
  if (!$processor_definition['import']) {
    throw new \Exception(sprintf('The %s processor does not support import operations.', $processor_id));
  }

  // Instantiate the processor plugin with default config values.
  $processor = $this->processorPluginManager
    ->createInstance($processor_id, $context);

  // Set and validate context values.
  if (isset($processor_definition['context'])) {
    foreach ($processor_definition['context'] as $name => $definition) {
      if (isset($context[$name])) {

        // @todo Validate context types and values.
        $processor
          ->setContextValue($name, $context[$name]);
      }
      else {

        // Handle missing required contexts.
        if ($definition
          ->isRequired()) {

          // @todo Handle this exception.
        }
      }
    }
  }
  return $processor;
}