You are here

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

Helper form builder for the targeting form.

2 calls to TargetingFormTrait::addTargetingForm()
AdminSettings::buildForm in src/Form/AdminSettings.php
Form constructor.
Tag::form in src/Form/Tag.php
Gets the actual form array to be built.

File

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

Class

TargetingFormTrait
Adds a form for saving DFP targeting information.

Namespace

Drupal\dfp\Form

Code

protected function addTargetingForm(array &$targeting_form, array $existing_targeting = []) {

  // Display settings.
  $targeting_form['targeting'] = [
    '#type' => 'markup',
    '#tree' => FALSE,
    '#prefix' => '<div id="dfp-targeting-wrapper">',
    '#suffix' => '</div>',
    '#element_validate' => [
      [
        get_class($this),
        'targetingFormValidate',
      ],
    ],
  ];
  $targeting_form['targeting']['table'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Target'),
      $this
        ->t('Value(s)'),
    ],
  ];

  // Add existing targets to the form unless they are empty.
  foreach ($existing_targeting as $key => $data) {
    $this
      ->addTargetForm($targeting_form, $key, $data);
  }

  // Add one blank set of target fields.
  $this
    ->addTargetForm($targeting_form, count($existing_targeting));
  $targeting_form['targeting']['dfp_more_targets'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add another target'),
    '#submit' => [
      get_class($this),
      'targetingFormMoreTargetsSubmit',
    ],
    '#limit_validation_errors' => [],
    '#ajax' => [
      'callback' => [
        get_class($this),
        'moreTargetsJs',
      ],
      'wrapper' => 'dfp-targeting-wrapper',
      'effect' => 'fade',
    ],
  ];

  // @todo Add token browser.
}