You are here

public function LogCommentForm::submitForm in Commerce Core 8.2

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

modules/log/src/Form/LogCommentForm.php, line 109

Class

LogCommentForm

Namespace

Drupal\commerce_log\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $log_storage = $this->entityTypeManager
    ->getStorage('commerce_log');
  assert($log_storage instanceof LogStorageInterface);
  $storage = $this->entityTypeManager
    ->getStorage($form_state
    ->getValue('source_entity_type'));
  assert($storage instanceof EntityStorageInterface);
  $entity = $storage
    ->load($form_state
    ->getValue('source_entity_id'));
  assert($entity instanceof ContentEntityInterface);
  $comment = nl2br(Html::escape($form_state
    ->getValue('comment')));
  $log_storage
    ->generate($entity, $form_state
    ->getValue('log_template_id'), [
    'comment' => $comment,
  ])
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Comment saved'));
}