You are here

public function Create::buildForm in SimpleAds 8

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

Class

Create
New advertisement form.

Namespace

Drupal\simpleads\Form\Ads

Code

public function buildForm(array $form, FormStateInterface $form_state, $type = NULL) {
  $ads = new Ads();
  $form['#attached']['library'][] = 'simpleads/admin.assets';
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Advertisement Name'),
    '#required' => TRUE,
    '#description' => $this
      ->t('This adminstrative name and visible to advertisement editors only'),
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#description' => $this
      ->t('The value of this field only visible to advertisement editors'),
  ];
  $form['url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('Redirect URL'),
    '#description' => $this
      ->t('Where to redirect when clicked'),
  ];
  $form['url_target'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Open Redirect URL in a new window'),
  ];
  $form = $ads
    ->getBuildForm($form, $form_state, $type);
  $form['group_id'] = [
    '#type' => 'select',
    '#options' => (new Groups())
      ->loadAsOptions(),
    '#title' => $this
      ->t('Advertisement Group'),
    '#description' => $this
      ->t('Where to redirect when clicked'),
  ];
  $form['campaign_id'] = [
    '#type' => 'select',
    '#options' => (new Campaigns())
      ->loadAsOptions(),
    '#title' => $this
      ->t('Advertisement Campaign'),
    '#description' => $this
      ->t('Where to redirect when clicked'),
  ];
  $form['status'] = [
    '#type' => 'select',
    '#options' => $ads
      ->getStatuses(),
    '#title' => $this
      ->t('Status'),
    '#description' => $this
      ->t('Where to redirect when clicked'),
    '#required' => TRUE,
  ];
  $form['ad_type'] = [
    '#type' => 'hidden',
    '#value' => $type,
  ];
  $form['ad_op'] = [
    '#type' => 'hidden',
    '#value' => 'create',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Create'),
    '#button_type' => 'primary',
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => Url::fromRoute('simpleads.ads'),
  ];
  return $form;
}