You are here

public function Edit::submitForm in SimpleAds 8

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

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/Ads/Edit.php, line 112

Class

Edit
Edit advertisement form.

Namespace

Drupal\simpleads\Form\Ads

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $id = $form_state
    ->getValue('id');
  $ads = (new Ads())
    ->setId($id)
    ->load();
  $type = $form_state
    ->getValue('ad_type');
  $options = $ads
    ->getOptions(TRUE);
  $options['url'] = $form_state
    ->getValue('url');
  $options['url_target'] = $form_state
    ->getValue('url_target');
  $options = $ads
    ->getSubmitForm('update', $options, $form_state, $type, $id);
  $ads
    ->setAdName($form_state
    ->getValue('name'))
    ->setDescription($form_state
    ->getValue('description'))
    ->setType($type)
    ->setGroup((new Groups())
    ->setId($form_state
    ->getValue('group_id'))
    ->load())
    ->setCampaign((new Campaigns())
    ->setId($form_state
    ->getValue('campaign_id'))
    ->load())
    ->setOptions($options)
    ->setStatus($form_state
    ->getValue('status'))
    ->setChangedAt()
    ->save();
  $form_state
    ->setRedirect('simpleads.ads');
}