function pardot_form_contact_message_form_alter in Pardot Integration 2.x
Same name and namespace in other branches
- 8 pardot.module \pardot_form_contact_message_form_alter()
Implements hook_form_FORM_ID_alter().
Add submit handler if the contact form has a Pardot mapping.
File
- ./
pardot.module, line 140 - Contains pardot.module.
Code
function pardot_form_contact_message_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// Get conditional state variable.
// @see \Drupal\pardot\EventSubscriber\PardotEventSubscriber
$include_tracking = (bool) \Drupal::state()
->get('pardot.include_tracking') ?: 0;
$config = \Drupal::config('pardot.settings');
if (NULL !== $config
->get('account_id') && $include_tracking) {
$bundle = FALSE;
$form_object = $form_state
->getFormObject();
if ($form_object instanceof MessageForm) {
/** @var \Drupal\contact\Entity\ContactForm $entity */
$bundle = $form_object
->getEntity()
->bundle();
$entity = \Drupal::entityTypeManager()
->getStorage('contact_form')
->load($bundle);
_set_pardot_form_submit($entity, $form, $form_state);
}
}
}