You are here

public function PardotScoreFormBase::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 score add/edit form.

Overrides EntityForm::buildForm

File

src/Form/PardotScoreFormBase.php, line 66

Class

PardotScoreFormBase
Class PardotScoreFormBase.

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);
  $score = $this->entity;

  // Build the form.
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $score
      ->label(),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $score
      ->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' => !$score
      ->isNew(),
  );
  $form['score_value'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Score Value'),
    '#description' => $this
      ->t('Assign a score value for the path configured below. This score will be assigned and reported Pardot.'),
    '#default_value' => $score->score_value,
  );

  // Set the path condition.
  if (isset($score->pages)) {
    $this->path_condition
      ->setConfiguration($score->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;
}