You are here

PardotFormMappingController.php in Pardot Integration 2.x

File

src/Controller/PardotFormMappingController.php
View source
<?php

namespace Drupal\pardot\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\pardot\Form\PardotFormMappingForm;

/**
 * Class PardotFormMappingController.
 */
class PardotFormMappingController extends ControllerBase {

  /**
   * Drupal\Core\Entity\EntityTypeManagerInterface definition.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

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

  /**
   * Renderform.
   *
   * @return array
   *   Return Hello string.
   */
  public function renderContactFormMapping($contact_form) {
    $entity = $this->entityTypeManager
      ->getStorage('contact_form')
      ->load($contact_form);
    if ($entity) {
      return \Drupal::formBuilder()
        ->getForm(PardotFormMappingForm::class, $entity, 'contact_form_mapping');
    }
    else {
      return [
        '#markup' => 'Could not find a matching entity.',
      ];
    }
  }

  /**
   * Renderform.
   *
   * @return array
   *   Return Hello string.
   */
  public function renderWebformFormMapping($webform) {
    $entity = $this->entityTypeManager
      ->getStorage('webform')
      ->load($webform);
    if ($entity) {
      return \Drupal::formBuilder()
        ->getForm(PardotFormMappingForm::class, $entity, 'webform_mapping');
    }
    else {
      return [
        '#markup' => 'Could not find a matching entity.',
      ];
    }
  }

}

Classes

Namesort descending Description
PardotFormMappingController Class PardotFormMappingController.