Commit a876d118 authored by Phuoc Hoang's avatar Phuoc Hoang Committed by James Gilliland
Browse files

Issue #3257493 by phoang: Add program_name to rest api POST request

parent 3feac50a
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ class MarketoMaWebformHandler extends WebformHandlerBase {
      'formid' => '',
      'marketo_ma_mapping' => [],
      'marketo_ma_list' => '',
      'program_name' => '',
    ];
  }

@@ -143,6 +144,13 @@ class MarketoMaWebformHandler extends WebformHandlerBase {
      '#default_value' => $this->configuration['marketo_ma_list'] ?? '',
    ];

    $form['program_name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Program Name'),
      '#description' => $this->t('Specify this to use Program Name'),
      '#default_value' => $this->configuration['program_name'] ?? '',
    ];

    $form['marketo_ma_mapping'] = [
      '#type' => 'webform_mapping',
      '#title' => $this->t('Webform to Marketo MA Lead mapping'),
@@ -178,6 +186,16 @@ class MarketoMaWebformHandler extends WebformHandlerBase {
        '@form' => $this->getWebform()->label(),
        'link' => $this->getWebform()->toLink($this->t('Edit'), 'handlers')->toString(),
      ];

      // Set programName when sync lead.
      // @todo needs to check for correct program name
      if (isset($this->configuration['program_name']) && $this->configuration['program_name'] !== '') {
        $lead->setProgramName($this->configuration['program_name']);
      }
      else {
        $this->getLogger()->error('@form webform failed to find the Program Name', $context);
      }

      if (isset($this->configuration['formid'])) {
        $lead->setFormId($this->configuration['formid']);
      }
+30 −0
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@ class Lead {
   */
  protected $formId;

  /**
   * Marketo program name.
   *
   * @var string
   */
  protected $programName;

  /**
   * Marketo tracking cookie.
   *
@@ -112,6 +119,16 @@ class Lead {
    return $this->formId;
  }

  /**
   * Get the program name if one is set.
   *
   * @return string|null
   *   The program name that should be used during sync if set.
   */
  public function getProgramName() {
    return $this->programName;
  }

  /**
   * Set a form ID.
   *
@@ -130,6 +147,19 @@ class Lead {
    return $this;
  }

  /**
   * Set a program name.
   *
   * @param string $programName
   *   The program name.
   *
   * @return $this
   */
  public function setProgramName($programName) {
    $this->programName = $programName;
    return $this;
  }

  /**
   * Get the current session "_mkto_trk" cookie value.
   *
+1 −0
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ class MarketoMaApiClient implements MarketoMaApiClientInterface {
  public function syncLead(Lead $lead, $key = 'email'): ?int {
    $request = new PushLeadToMarketoRequest([
      'input' => [$this->mapLeadToRest($lead)],
      'program_name' => $lead->getProgramName(),
      'lookup_field' => $key,
    ]);
    $response = $this->leadsApi->pushToMarketoUsingPOST($request);