You are here

protected function BreakpointFormTrait::addBreakpointForm in Doubleclick for Publishers (DFP) 8

Helper form builder for an individual breakpoint.

1 call to BreakpointFormTrait::addBreakpointForm()
BreakpointFormTrait::addBreakpointsForm in src/Form/BreakpointFormTrait.php
Helper form builder for the breakpoints form.

File

src/Form/BreakpointFormTrait.php, line 143
Contains \Drupal\dfp\Form\BreakpointFormTrait.

Class

BreakpointFormTrait
Provides form for adding breakpoints to a DFP tag.

Namespace

Drupal\dfp\Form

Code

protected function addBreakpointForm(array &$form, $key, array $data = []) {
  $form['breakpoints']['table'][$key] = [
    '#prefix' => '<div class="breakpoint" id="breakpoint-' . $key . '">',
    '#suffix' => '</div>',
    '#element_validate' => [
      [
        get_class($this),
        'breakpointFormValidate',
      ],
    ],
  ];
  $form['breakpoints']['table'][$key]['browser_size'] = [
    '#type' => 'textfield',
    '#title_display' => 'invisible',
    '#title' => $this
      ->t('Minimum Browser Size'),
    '#size' => 10,
    '#default_value' => isset($data['browser_size']) ? $data['browser_size'] : '',
    '#parents' => [
      'breakpoints',
      $key,
      'browser_size',
    ],
    '#attributes' => [
      'class' => [
        'field-breakpoint-browser-size',
      ],
    ],
  ];
  $form['breakpoints']['table'][$key]['ad_sizes'] = [
    '#type' => 'textfield',
    '#title_display' => 'invisible',
    '#title' => $this
      ->t('Ad Sizes'),
    '#size' => 20,
    '#default_value' => isset($data['ad_sizes']) ? $data['ad_sizes'] : '',
    '#parents' => [
      'breakpoints',
      $key,
      'ad_sizes',
    ],
    '#attributes' => [
      'class' => [
        'field-breakpoint-ad-sizes',
      ],
    ],
  ];
  if (empty($data)) {
    $form['breakpoints']['table'][$key]['browser_size']['#description'] = $this
      ->t('Example: 1024x768');
    $form['breakpoints']['table'][$key]['ad_sizes']['#description'] = $this
      ->t('Example: 300x600, 300x250. Enter "@none" to suppress this slot for a given browser size.', array(
      '@none' => '<none>',
    ));
  }
}