You are here

public function GoogleImageSitemapCreateForm::submitForm in Google Image Sitemap 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/GoogleImageSitemapCreateForm.php \Drupal\google_image_sitemap\Form\GoogleImageSitemapCreateForm::submitForm()
  2. 1.0.x src/Form/GoogleImageSitemapCreateForm.php \Drupal\google_image_sitemap\Form\GoogleImageSitemapCreateForm::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/GoogleImageSitemapCreateForm.php, line 77

Class

GoogleImageSitemapCreateForm
Provides a form to create new sitemap.

Namespace

Drupal\google_image_sitemap\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $sitemap_obj = (object) $form_state
    ->getValues();
  $sitemap_id = \Drupal::routeMatch()
    ->getRawParameter('sitemap_id');

  // Set created key if new.
  if (empty($sitemap_id)) {
    $sitemap['created'] = \Drupal::time()
      ->getRequestTime();
  }
  $sitemap['node_type'] = $sitemap_obj->node_type;
  $sitemap['license'] = $sitemap_obj->license;
  $sitemap['last_updated'] = \Drupal::time()
    ->getRequestTime();
  $sitemap_obj->sid = $form_state
    ->getStorage();
  \Drupal::database()
    ->merge('google_image_sitemap')
    ->fields($sitemap)
    ->condition('sid', $sitemap_id)
    ->execute();

  // Redirect to main page of sitemap.
  $form_state
    ->setRedirect('google_image_sitemap.list');
}