You are here

public function PardotCampaignFormBase::buildForm in Pardot Integration 8

Overrides Drupal\Core\Entity\EntityFormController::form().

Builds the entity add/edit form.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: An associative array containing the current state of the form.

Return value

array An associative array containing the campaign add/edit form.

Overrides EntityForm::buildForm

File

src/Form/PardotCampaignFormBase.php, line 66

Class

PardotCampaignFormBase
Class PardotCampaignFormBase.

Namespace

Drupal\pardot\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get anything we need from the base class.
  $form = parent::buildForm($form, $form_state);
  $campaign = $this->entity;

  // Build the form.
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $campaign
      ->label(),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $campaign
      ->id(),
    '#machine_name' => array(
      'exists' => array(
        $this,
        'exists',
      ),
      'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
      'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
    ),
    '#disabled' => !$campaign
      ->isNew(),
  );
  $form['campaign_id'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Pardot Campaign ID'),
    '#description' => $this
      ->t('Numeric campaign code(piCId) from the tracking code preview in Pardot administration interface.'),
    '#default_value' => $campaign->campaign_id,
  );

  // Set the path condition.
  if (isset($campaign->pages)) {
    $this->path_condition
      ->setConfiguration($campaign->pages);
  }
  else {
    $this->path_condition
      ->setConfiguration(array());
  }

  // Build the path_condition configuration form elements.
  $form += $this->path_condition
    ->buildConfigurationForm($form, $form_state);
  unset($form['negate']);

  // Return the form.
  return $form;
}