You are here

public function All::buildForm in SimpleAds 8

Same name in this branch
  1. 8 src/Form/Groups/All.php \Drupal\simpleads\Form\Groups\All::buildForm()
  2. 8 src/Form/Ads/All.php \Drupal\simpleads\Form\Ads\All::buildForm()
  3. 8 src/Form/Campaigns/All.php \Drupal\simpleads\Form\Campaigns\All::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/Campaigns/All.php, line 25

Class

All
Configure SimpleAdsCampaigns settings.

Namespace

Drupal\simpleads\Form\Campaigns

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attached']['library'][] = 'simpleads/admin.assets';
  $campaigns = new Campaigns();
  $form = $this
    ->actionDropdown($form, $campaigns
    ->getTypes());
  $form['campaigns'] = [
    '#type' => 'table',
    '#tableselect' => FALSE,
    '#tabledrag' => FALSE,
    '#empty' => $this
      ->t('There are no campaigns created.'),
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Description'),
      $this
        ->t('Type'),
      $this
        ->t('Status'),
      '',
    ],
  ];
  foreach ($campaigns
    ->loadAll() as $item) {
    $id = $item
      ->getId();
    $type = $item
      ->getType();
    $form['campaigns'][$id]['name'] = [
      '#markup' => $item
        ->getCampaignName(),
    ];
    $form['campaigns'][$id]['description'] = [
      '#markup' => $item
        ->getDescription(),
    ];
    $form['campaigns'][$id]['type'] = [
      '#markup' => $campaigns
        ->getName($type),
    ];
    $form['campaigns'][$id]['status'] = [
      '#markup' => $item
        ->getStatusName($item
        ->getStatus()),
    ];
    $form['campaigns'][$id]['ops'] = [
      '#type' => 'operations',
      '#links' => [
        'edit' => [
          'title' => $this
            ->t('Edit'),
          'url' => Url::fromRoute('simpleads.campaigns.edit', [
            'type' => $type,
            'id' => $id,
          ]),
        ],
        'delete' => [
          'title' => $this
            ->t('Delete'),
          'url' => Url::fromRoute('simpleads.campaigns.delete', [
            'type' => $type,
            'id' => $id,
          ]),
        ],
      ],
    ];
  }
  return $form;
}