You are here

protected function TargetingFormTrait::addTargetForm in Doubleclick for Publishers (DFP) 8

Helper form builder for an individual target.

1 call to TargetingFormTrait::addTargetForm()
TargetingFormTrait::addTargetingForm in src/Form/TargetingFormTrait.php
Helper form builder for the targeting form.

File

src/Form/TargetingFormTrait.php, line 100
Contains \Drupal\dfp\Form\TargetingFormTrait.

Class

TargetingFormTrait
Adds a form for saving DFP targeting information.

Namespace

Drupal\dfp\Form

Code

protected function addTargetForm(array &$form, $key, array $data = []) {
  $form['targeting']['table'][$key] = [
    '#prefix' => '<div class="target" id="target-' . $key . '">',
    '#suffix' => '</div>',
    '#element_validate' => [
      [
        get_class($this),
        'targetFormValidate',
      ],
    ],
  ];
  $form['targeting']['table'][$key]['target'] = [
    '#type' => 'textfield',
    '#title_display' => 'invisible',
    '#title' => $this
      ->t('Target Name'),
    '#size' => 10,
    '#default_value' => isset($data['target']) ? $data['target'] : '',
    '#parents' => [
      'targeting',
      $key,
      'target',
    ],
    '#attributes' => [
      'class' => [
        'field-target-target',
      ],
    ],
  ];
  $form['targeting']['table'][$key]['value'] = [
    '#type' => 'textfield',
    '#title_display' => 'invisible',
    '#title' => $this
      ->t('Target Value'),
    '#size' => 20,
    '#default_value' => isset($data['value']) ? $data['value'] : '',
    '#parents' => [
      'targeting',
      $key,
      'value',
    ],
    '#attributes' => [
      'class' => [
        'field-target-value',
      ],
    ],
  ];
  if (empty($data)) {
    $form['targeting']['table'][$key]['target']['#description'] = $this
      ->t('Example: color');
    $form['targeting']['table'][$key]['value']['#description'] = $this
      ->t('Example: red,white,blue');
  }
}