Skip to content
Snippets Groups Projects
Commit 84249cb1 authored by Dimitris Bozelos's avatar Dimitris Bozelos
Browse files

Issue #3357779 Added runner service for entity operations

parent 5e0ce912
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,13 @@ services:
- '@logger.channel.acumatica'
- '@entity_sync.import.manager'
acumatica.entity_sync_runner.entity:
class: Drupal\acumatica\EntitySync\Runner\Entity
arguments:
- '@entity_type.manager'
- '@logger.channel.acumatica'
- '@entity_sync.export.entity_manager'
## Subscribers.
acumatica.entity_sync_subscriber.variation_import_remote_entity_mapping:
class: Drupal\acumatica\EventSubscriber\VariationImportRemoteEntityMapping
......
......
<?php
declare(strict_types=1);
namespace Drupal\acumatica\EntitySync\Runner;
use Drupal\entity_sync\MachineName\Field\Operation as OperationField;
use Drupal\entity_sync\Entity\OperationInterface;
use Drupal\entity_sync\Export\EntityManagerInterface as ExportManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Psr\Log\LoggerInterface;
/**
* Runner for operation configurator plugins that operate on single entities.
*
* Currently only supports exporting individual entities. Support for importing
* individual entities will be added here.
*/
class Entity extends Base {
/**
* Constructs a new Entity object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Psr\Log\LoggerInterface $logger
* The module's logger channel.
* @param \Drupal\entity_sync\Export\EntityManagerInterface $exportManager
* The Entity Synchronization entity export manager.
*/
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager,
protected LoggerInterface $logger,
protected ExportManagerInterface $exportManager
) {
parent::__construct($this->entityTypeManager, $this->logger);
}
/**
* {@inheritdoc}
*
* Supported context options are:
* - options (array) An associative array with options to pass to the export
* manager. The operation entity is passed in the context automatically.
*
* @see \Drupal\entity_sync\Import\ManagerInterface::exportLocalEntity()
*/
protected function doRun(
OperationInterface $operation,
array $context
): void {
$options = $context['options'] ?? [];
if (!isset($options['context'])) {
$options['context'] = [];
}
$options['context']['operation_entity'] = $operation;
$this->exportManager->exportLocalEntity(
$operation->bundle(),
$operation->get(OperationField::ENTITY)->entity,
$options
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment