Skip to content
Snippets Groups Projects
Commit 570b072a authored by Aaron Bauman's avatar Aaron Bauman
Browse files

by aaronbauman - refine PushParams class and events

parent 8d935598
No related branches found
No related tags found
No related merge requests found
......@@ -245,10 +245,10 @@ class MappedObject extends RevisionableContentEntityBase implements MappedObject
// SalesforcePushEvent constructor - both $mapping and $drupal_entity are
// being sent already, so why create the $params twice? - AJR
// previously hook_salesforce_push_params_alter
$params = $mapping->getPushParams($drupal_entity);
$params = new PushParams($drupal_entity, $mapping);
\Drupal::service('event_dispatcher')->dispatch(
SalesforceEvents::PUSH_PARAMS,
new SalesforcePushEvent($drupal_entity, $mapping, $this, $params)
new SalesforcePushEvent($this, $params)
);
// @TODO is this the right place for this logic to live?
......
......@@ -175,28 +175,6 @@ class SalesforceMapping extends ConfigEntityBase implements SalesforceMappingInt
return parent::save();
}
/**
* Given a Drupal entity, return an array of Salesforce key-value pairs
* previously salesforce_push_map_params (d7)
*
* @param object $entity
* Entity wrapper object.
*
* @return Drupal\salesforce_mapping\PushParams
*/
public function getPushParams(EntityInterface $entity) {
// @TODO This should probably be delegated to a field plugin bag?
$params = new PushParams([]);
foreach ($this->getFieldMappings() as $field_plugin) {
// Skip fields that aren't being pushed to Salesforce.
if (!$field_plugin->push()) {
continue;
}
$params->setParam($field_plugin->config('salesforce_field'), $field_plugin->value($entity));
}
return $params;
}
/**
* Given a Salesforce object, return an array of Drupal entity key-value pairs
*
......
......@@ -3,6 +3,8 @@
namespace Drupal\salesforce_mapping;
use Symfony\Component\EventDispatcher\Event;
use Drupal\salesforce_mapping\Entity\SalesforceMappingInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Wrapper for the array of values which will be pushed to Salesforce.
......@@ -11,10 +13,36 @@ use Symfony\Component\EventDispatcher\Event;
class PushParams {
protected $params;
protected $mapping;
protected $drupal_entity;
public function __construct(array $params) {
/**
* Given a Drupal entity, return an array of Salesforce key-value pairs
* previously salesforce_push_map_params (d7)
*
* @param SalesforceMappingInterface $mapping
* @param EntityInterface $entity
* @param array $params (optional)
*/
public function __construct(SalesforceMappingInterface $mapping, EntityInterface $entity, array $params = []) {
$this->mapping = $mapping;
$this->drupal_entity = $entity;
$this->params = $params;
return $this;
foreach ($mapping->getFieldMappings() as $field_plugin) {
// Skip fields that aren't being pushed to Salesforce.
if (!$field_plugin->push()) {
continue;
}
$this->param[$field_plugin->config('salesforce_field')] = $field_plugin->value($entity);
}
}
public function getMapping() {
return $this->mapping;
}
public function getDrupalEntity() {
return $this->drupal_entity;
}
public function getParams() {
......
......@@ -14,9 +14,7 @@ class SalesforcePushEvent extends Event {
protected $mapped_object;
protected $entity;
public function __construct(EntityInterface $entity, SalesforceMappingInterface $mapping, MappedObjectInterface $mapped_object = NULL, PushParams $params = NULL) {
$this->entity = $entity;
$this->mapping = $mapping;
public function __construct(MappedObjectInterface $mapped_object = NULL, PushParams $params = NULL) {
$this->mapped_object = $mapped_object;
$this->params = $params;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment