You are here

class PardotFormMappingForm in Pardot Integration 2.x

Class PardotFormMappingForm.

Hierarchy

Expanded class hierarchy of PardotFormMappingForm

1 file declares its use of PardotFormMappingForm
PardotFormMappingController.php in src/Controller/PardotFormMappingController.php
2 string references to 'PardotFormMappingForm'
pardot.routing.yml in ./pardot.routing.yml
pardot.routing.yml
pardot.routing.yml in ./pardot.routing.yml
pardot.routing.yml

File

src/Form/PardotFormMappingForm.php, line 13

Namespace

Drupal\pardot\Form
View source
class PardotFormMappingForm extends FormBase {

  /**
   * Drupal\pardot\Plugin\FormMapHandlerPluginManager definition.
   *
   * @var \Drupal\pardot\Plugin\FormMapHandlerPluginManager
   */
  protected $pluginManagerFormMapHandlerPlugin;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->pluginManagerFormMapHandlerPlugin = $container
      ->get('plugin.manager.form_map_handler_plugin');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'pardot_form_mapping_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $formMapPluginManager = $this->pluginManagerFormMapHandlerPlugin;
    $entity = func_get_args()[2];
    $form_map_plugin_instance_id = func_get_args()[3] ?? '';
    if ($entity && $form_map_plugin_instance_id) {
      $form_state
        ->set('entity', $entity);
      $form_state
        ->set('form_map_plugin_instance_id', $form_map_plugin_instance_id);
      $plugin = $formMapPluginManager
        ->createInstance($form_map_plugin_instance_id);
      $settings = [
        $entity
          ->getEntityTypeId() => $entity
          ->id(),
        'entity_id' => $entity
          ->id(),
      ];
      if ($plugin_settings = $entity
        ->getThirdPartySetting('pardot', 'pardot_form_mapping_plugin', FALSE)) {
        $settings['settings'] = $plugin_settings['settings'];
      }
      $plugin
        ->setConfiguration($settings);
      $form['pardot_form_mapping'] = PluginSubFormHelpers::buildPluginForm($plugin, $form, $form_state, [
        'pardot_form_mapping',
      ]);
    }
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Submit'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    // Display result.
    $values = $form_state
      ->getValues();
    $pardot_form_mapping = $values['pardot_form_mapping'] ?? FALSE;
    $entity = $form_state
      ->get('entity');
    $form_map_plugin_instance_id = $form_state
      ->get('form_map_plugin_instance_id');
    if ($pardot_form_mapping && $form_map_plugin_instance_id && $entity) {
      $plugin = $this->pluginManagerFormMapHandlerPlugin;
      $plugin = $plugin
        ->createInstance($form_map_plugin_instance_id);
      $plugin = PluginSubFormHelpers::pluginSubmit($plugin, $form, $form_state, [
        'pardot_form_mapping',
      ]);
      $entity
        ->setThirdPartySetting('pardot', 'pardot_form_mapping_plugin', $plugin
        ->getConfiguration());
      $entity
        ->save();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PardotFormMappingForm::$pluginManagerFormMapHandlerPlugin protected property Drupal\pardot\Plugin\FormMapHandlerPluginManager definition.
PardotFormMappingForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
PardotFormMappingForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
PardotFormMappingForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
PardotFormMappingForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
PardotFormMappingForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.