You are here

public function Edit::buildForm in SimpleAds 8

Same name in this branch
  1. 8 src/Form/Groups/Edit.php \Drupal\simpleads\Form\Groups\Edit::buildForm()
  2. 8 src/Form/Ads/Edit.php \Drupal\simpleads\Form\Ads\Edit::buildForm()
  3. 8 src/Form/Campaigns/Edit.php \Drupal\simpleads\Form\Campaigns\Edit::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/Edit.php, line 33

Class

Edit
Edit advertisement campaign form.

Namespace

Drupal\simpleads\Form\Campaigns

Code

public function buildForm(array $form, FormStateInterface $form_state, $type = NULL, $id = NULL) {
  $campaigns = (new Campaigns())
    ->setId($id)
    ->load();
  $form['#attached']['library'][] = 'simpleads/admin.assets';
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Campaign Name'),
    '#required' => TRUE,
    '#description' => $this
      ->t('This adminstrative name and visible to advertisement editors only.'),
    '#default_value' => $campaigns
      ->getCampaignName(),
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#description' => $this
      ->t('The value of this field only visible to advertisement editors.'),
    '#default_value' => $campaigns
      ->getDescription(),
  ];
  $form = $campaigns
    ->getBuildForm($form, $form_state, $type, $id);
  $form['status'] = [
    '#type' => 'select',
    '#options' => $campaigns
      ->getStatuses(),
    '#title' => $this
      ->t('Status'),
    '#description' => $this
      ->t('Where to redirect when clicked'),
    '#required' => TRUE,
    '#default_value' => $campaigns
      ->getStatus(),
  ];
  $form['campaign_type'] = [
    '#type' => 'hidden',
    '#value' => $type,
  ];
  $form['id'] = [
    '#type' => 'hidden',
    '#value' => $id,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update'),
    '#button_type' => 'primary',
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => Url::fromRoute('simpleads.campaigns'),
  ];
  return $form;
}