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/ Groups/ All.php, line 25
Class
- All
- Configure SimpleAdsGroups settings.
Namespace
Drupal\simpleads\Form\GroupsCode
public function buildForm(array $form, FormStateInterface $form_state) {
$groups = new Groups();
$form['#attached']['library'][] = 'simpleads/admin.assets';
$form['actions'] = [
'#type' => 'actions',
'#weight' => -10,
];
$form['actions']['links'] = [
'#type' => 'link',
'#title' => $this
->t('+ New Group'),
'#url' => Url::fromRoute('simpleads.groups.new'),
'#attributes' => [
'class' => [
'button',
'button--primary',
'form-submit',
],
],
'#prefix' => '<div class="simpleads-actions-wrapper single">',
'#suffix' => '</div>',
];
$form['groups'] = [
'#type' => 'table',
'#tableselect' => FALSE,
'#tabledrag' => FALSE,
'#empty' => $this
->t('There are no groups created. Please consider keeping ads with the same width in the same group so it gets properly rendered in blocks.'),
'#header' => [
$this
->t('Name'),
$this
->t('Description'),
'',
],
];
foreach ($groups
->loadAll() as $item) {
$id = $item
->getId();
$form['groups'][$id]['name'] = [
'#markup' => $item
->getGroupName(),
];
$form['groups'][$id]['description'] = [
'#markup' => $item
->getDescription(),
];
$form['groups'][$id]['ops'] = [
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('simpleads.groups.edit', [
'id' => $id,
]),
],
'delete' => [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('simpleads.groups.delete', [
'id' => $id,
]),
],
],
];
}
return $form;
}