You are here

public function FormMap::__construct in Pardot Integration 2.x

File

src/FormMap.php, line 34

Class

FormMap
Provides an interface for defining Pardot Form Map entities.

Namespace

Drupal\pardot

Code

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);
}