You are here

class FormMap in Pardot Integration 2.x

Provides an interface for defining Pardot Form Map entities.

Hierarchy

Expanded class hierarchy of FormMap

4 files declare their use of FormMap
ContactFormMapping.php in src/Plugin/FormMapHandlerPlugin/ContactFormMapping.php
FormMapHandlerPluginInterface.php in src/Plugin/FormMapHandlerPluginInterface.php
pardot.module in ./pardot.module
Contains pardot.module.
WebformMapping.php in src/Plugin/FormMapHandlerPlugin/WebformMapping.php

File

src/FormMap.php, line 8

Namespace

Drupal\pardot
View source
class FormMap implements FormMapInterface {

  /**
   * The post url provided by the pardot form handler.
   *
   * @var string
   */
  protected $post_url;

  /**
   * The array of mapped contact form fields to pardot form handler fields.
   *
   * @var array
   */
  public $settings = [];

  /**
   * The array of mapped contact form fields to pardot form handler fields.
   *
   * @var array
   */
  public $mapping = [];

  /**
   * {@inheritdoc}
   */
  public function __construct($settings) {
    $mapping = [];
    $this->settings = $settings;
    $form_map_plugin_manager = \Drupal::service('plugin.manager.pardot_form_map_formatter_plugin');
    if (isset($this->settings['form_map'])) {
      foreach ($this->settings['form_map'] as $key => $setting) {
        if ($setting['plugin_type']) {
          $plugin = $form_map_plugin_manager
            ->createInstance($setting['plugin']['id']);
          $plugin
            ->setConfiguration($setting['plugin']);
        }
        else {
          $plugin = [];
        }
        $class = $setting['class'];
        $mapping[$key] = new $class($setting['pardot_key'], $setting['plugin_type'], $plugin);
      }
    }
    $post_url = $this->settings['post_url'] ?? '';
    $this
      ->setPostUrl($post_url);
    $this
      ->setMappedFieldCollection($mapping);
  }

  /**
   * {@inheritdoc}
   */
  public function getPostUrl() {
    return $this->post_url;
  }

  /**
   * {@inheritdoc}
   */
  public function setPostUrl(string $post_url) {
    $this->post_url = $post_url;
  }

  /**
   * {@inheritdoc}
   */
  public function getMappedFieldCollection() {
    return $this->mapping;
  }

  /**
   * {@inheritdoc}
   */
  public function setMappedFieldCollection(array $mapping) {
    $this->mapping = $mapping;
  }

  /**
   * Add a new MappedField instance to the collection array.
   *
   * @param string $class
   *   The specific class name.
   * @param string $pardot_key
   *   The name of the pardot field.
   * @param string $plugin_type
   *   The machine name of the selected plugin.
   * @param mixed $plugin
   *   The plugin instance or empty array.
   * @param array $config
   *   Pass some optional init config to the plugin.
   */
  public function appendMappedField(string $class = '\\Drupal\\pardot\\MappedField', string $pardot_key = '', string $plugin_type = '', $plugin = [], array $config = []) {
    $this->mapping[] = new $class($pardot_key, $plugin_type, $plugin, $config);
  }

  /**
   * Retrieve a particular row from the MappedField collection.
   *
   * @param int $key
   *   The index where the MappedField lives.
   *
   * @return mixed
   *   Return the instance of MappedFieldInterface or null.
   */
  public function getMappedField(int $key) {
    if (isset($this->mapping[$key])) {
      return $this->mapping[$key];
    }
    return NULL;
  }

  /**
   * Remove a particular row from the MappedField collection.
   *
   * @param int $key
   *   The index where the instance of MappedFieldInterface lives.
   */
  public function removeMappedField(int $key) {
    if (isset($this->mapping[$key])) {
      unset($this->mapping[$key]);
    }
  }
  public function toArray() {
    $mapping = $this->mapping;
    $mapping = array_map(function (MappedFieldInterface $mapping) {
      return $mapping
        ->toArray();
    }, $mapping);
    $this->settings['post_url'] = $this
      ->getPostUrl();
    $this->settings['form_map'] = $mapping;
    return $this->settings;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormMap::$mapping public property The array of mapped contact form fields to pardot form handler fields.
FormMap::$post_url protected property The post url provided by the pardot form handler.
FormMap::$settings public property The array of mapped contact form fields to pardot form handler fields.
FormMap::appendMappedField public function Add a new MappedField instance to the collection array.
FormMap::getMappedField public function Retrieve a particular row from the MappedField collection.
FormMap::getMappedFieldCollection public function Get the array of MappedField instances. Overrides FormMapInterface::getMappedFieldCollection
FormMap::getPostUrl public function Get the form handler post url. Overrides FormMapInterface::getPostUrl
FormMap::removeMappedField public function Remove a particular row from the MappedField collection.
FormMap::setMappedFieldCollection public function Set the array of field map configurations. Overrides FormMapInterface::setMappedFieldCollection
FormMap::setPostUrl public function Set the form handler post uri. Overrides FormMapInterface::setPostUrl
FormMap::toArray public function
FormMap::__construct public function