public function All::buildForm in SimpleAds 8
Same name in this branch
- 8 src/Form/Groups/All.php \Drupal\simpleads\Form\Groups\All::buildForm()
- 8 src/Form/Ads/All.php \Drupal\simpleads\Form\Ads\All::buildForm()
- 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/ Ads/ All.php, line 25
Class
- All
- Advertisement listing form.
Namespace
Drupal\simpleads\Form\AdsCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'simpleads/admin.assets';
$form['actions'] = [
'#type' => 'actions',
'#weight' => -10,
];
$ads = new Ads();
$form = $this
->actionDropdown($form, $ads
->getTypes());
$form['advertisements'] = [
'#type' => 'table',
'#tableselect' => FALSE,
'#tabledrag' => FALSE,
'#empty' => $this
->t('There are no advertisements created. Please create new Group first.'),
'#header' => [
$this
->t('Name'),
$this
->t('Type'),
$this
->t('Group'),
$this
->t('Campaign'),
$this
->t('Status'),
'',
],
];
foreach ($ads
->loadAll() as $item) {
$id = $item
->getId();
$type = $item
->getType();
$group = $item
->getGroup()
->getGroupName();
$campaign = $item
->getCampaign()
->getCampaignName();
$form['advertisements'][$id]['name'] = [
'#markup' => $item
->getAdName(),
];
$form['advertisements'][$id]['type'] = [
'#markup' => $item
->getName($type),
];
$form['advertisements'][$id]['group'] = [
'#markup' => !empty($group) ? $group : '-',
];
$form['advertisements'][$id]['campaign'] = [
'#markup' => !empty($campaign) ? $campaign : '-',
];
$form['advertisements'][$id]['status'] = [
'#markup' => $item
->getStatusName($item
->getStatus()),
];
$form['advertisements'][$id]['ops'] = [
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('simpleads.ads.edit', [
'type' => $type,
'id' => $id,
]),
],
'delete' => [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('simpleads.ads.delete', [
'type' => $type,
'id' => $id,
]),
],
],
];
}
return $form;
}