You are here

public function PageJsonForm::submitForm in Structured Data (JSON+LD Rich Snippets) 8

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/PageJsonForm.php, line 84

Class

PageJsonForm
Class PageJsonForm.

Namespace

Drupal\structured_data\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $entity = [
    'route_name' => $form_state
      ->getValue('route_name'),
    'url' => $form_state
      ->getValue('url'),
    'bundle' => $form_state
      ->getValue('bundle'),
    'entity_id' => $form_state
      ->getValue('entity_id'),
    'json' => $form_state
      ->getValue('json'),
    'updated_by' => $this
      ->currentUser()
      ->id(),
    'updated_time' => time(),
  ];
  Helper::updatePageJson($entity);
  $this
    ->messenger()
    ->addMessage($this
    ->t('Page Json updated successfully.'));
  if (!empty($entity['url'])) {
    $url = Url::fromUri('internal:' . $entity['url']);
    $form_state
      ->setRedirectUrl($url);
  }
}