You are here

public function SimpleAds::blockForm in SimpleAds 8

Returns the configuration form elements specific to this block plugin.

Blocks that need to add form elements to the normal block configuration form should implement this method.

Parameters

array $form: The form definition array for the block configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The renderable form array representing the entire configuration form.

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/SimpleAds.php, line 24

Class

SimpleAds
SimpleAds Advertisement block

Namespace

Drupal\simpleads\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $config = $this
    ->getConfiguration();
  $form = parent::blockForm($form, $form_state);
  $groups = new Groups();
  $items = [];
  $items[''] = $this
    ->t('- none -');
  foreach ($groups
    ->loadAll() as $item) {
    $items[$item
      ->getId()] = $item
      ->getGroupName();
  }
  $form['sizes'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Min Width'),
      $this
        ->t('Group'),
      '',
    ],
    '#tableselect' => FALSE,
    '#tabledrag' => FALSE,
  ];
  for ($i = 0; $i < 4; $i++) {
    $form['sizes'][$i]['minWidth'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Min Width'),
      '#description' => $this
        ->t('Specifies the minimum width of the viewport. Example: minWidth: 1024.'),
      '#default_value' => !empty($config['sizes'][$i]['minWidth']) ? $config['sizes'][$i]['minWidth'] : '',
      '#size' => 10,
    ];
    $form['sizes'][$i]['group_id'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Group'),
      '#description' => $this
        ->t('Select a group of ads to display in speficied view breakpoint (responsive).'),
      '#options' => $items,
      '#default_value' => !empty($config['sizes'][$i]['group_id']) ? $config['sizes'][$i]['group_id'] : '',
    ];
  }
  return $form;
}