You are here

class PushParams in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/src/PushParams.php \Drupal\salesforce_mapping\PushParams
  2. 8.3 modules/salesforce_mapping/src/PushParams.php \Drupal\salesforce_mapping\PushParams

Wrapper for the array of values which will be pushed to Salesforce.

Usable by salesforce.client for push actions: create, upsert, update.

Hierarchy

Expanded class hierarchy of PushParams

4 files declare their use of PushParams
MappedObject.php in modules/salesforce_mapping/src/Entity/MappedObject.php
PullBase.php in modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php
PushParamsTest.php in modules/salesforce_mapping/tests/src/Functional/PushParamsTest.php
SalesforcePushParamsEvent.php in modules/salesforce_mapping/src/Event/SalesforcePushParamsEvent.php

File

modules/salesforce_mapping/src/PushParams.php, line 13

Namespace

Drupal\salesforce_mapping
View source
class PushParams {

  /**
   * Key-value array of raw data.
   *
   * @var array
   */
  protected $params;

  /**
   * Mapping for this push params.
   *
   * @var \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface
   */
  protected $mapping;

  /**
   * The Drupal entity being parameterized.
   *
   * @var \Drupal\Core\Entity\EntityInterface
   */
  protected $drupalEntity;

  /**
   * Given a Drupal entity, return an array of Salesforce key-value pairs.
   *
   * @param \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface $mapping
   *   Salesforce Mapping.
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   Drupal entity.
   * @param array $params
   *   Initial params values (optional).
   */
  public function __construct(SalesforceMappingInterface $mapping, EntityInterface $entity, array $params = []) {
    $this->mapping = $mapping;
    $this->drupalEntity = $entity;
    $this->params = $params;
    foreach ($mapping
      ->getFieldMappings() as $field_plugin) {

      // Skip fields that aren't being pushed to Salesforce.
      if (!$field_plugin
        ->push()) {
        continue;
      }
      $this->params[$field_plugin
        ->config('salesforce_field')] = $field_plugin
        ->pushValue($entity, $mapping);
    }
  }

  /**
   * Getter.
   *
   * @return \Drupal\salesforce_mapping\Entity\SalesforceMappingInterface
   *   Mapping.
   */
  public function getMapping() {
    return $this->mapping;
  }

  /**
   * Getter.
   *
   * @return \Drupal\Core\Entity\FieldableEntityInterface
   *   Drupal entity.
   */
  public function getDrupalEntity() {
    return $this->drupalEntity;
  }

  /**
   * Get the raw push data.
   *
   * @return array
   *   The push data.
   */
  public function getParams() {
    return $this->params;
  }

  /**
   * Get a param value for a given key.
   *
   * @param string $key
   *   A param key.
   *
   * @return mixed|null
   *   The given param value for $key, or NULL if $key is not set.
   *
   * @see hasParam()
   */
  public function getParam($key) {
    return static::hasParam($key) ? $this->params[$key] : NULL;
  }

  /**
   * Return TRUE if the given $key is set.
   *
   * @param string $key
   *   A key.
   *
   * @return bool
   *   TRUE if $key is set.
   */
  public function hasParam($key) {
    return array_key_exists($key, $this->params);
  }

  /**
   * Overwrite params wholesale.
   *
   * @param array $params
   *   Array of params to set for thie PushParams.
   *
   * @return $this
   */
  public function setParams(array $params) {
    $this->params = $params;
    return $this;
  }

  /**
   * Set a param.
   *
   * @param string $key
   *   Key to set for this param.
   * @param mixed $value
   *   Value to set for this param.
   *
   * @return $this
   */
  public function setParam($key, $value) {
    $this->params[$key] = $value;
    return $this;
  }

  /**
   * Unset a param value.
   *
   * @param string $key
   *   Key to unset for this param.
   *
   * @return $this
   */
  public function unsetParam($key) {
    unset($this->params[$key]);
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PushParams::$drupalEntity protected property The Drupal entity being parameterized.
PushParams::$mapping protected property Mapping for this push params.
PushParams::$params protected property Key-value array of raw data.
PushParams::getDrupalEntity public function Getter.
PushParams::getMapping public function Getter.
PushParams::getParam public function Get a param value for a given key.
PushParams::getParams public function Get the raw push data.
PushParams::hasParam public function Return TRUE if the given $key is set.
PushParams::setParam public function Set a param.
PushParams::setParams public function Overwrite params wholesale.
PushParams::unsetParam public function Unset a param value.
PushParams::__construct public function Given a Drupal entity, return an array of Salesforce key-value pairs.