You are here

public function StatusForm::generatePreview in Heartbeat 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.

Throws

\Drupal\Core\Entity\EntityStorageException

\InvalidArgumentException

File

modules/statusmessage/src/Form/StatusForm.php, line 183

Class

StatusForm
Form controller for Status edit forms.

Namespace

Drupal\statusmessage\Form

Code

public function generatePreview(array &$form, FormStateInterface $form_state) {
  $message = $form_state
    ->getValue('message');
  preg_match_all('#\\bhttps?://[^,\\s()<>]+(?:\\([\\w\\d]+\\)|([^,[:punct:]\\s]|/))#', $message, $match);
  if ($this->markupgenerator !== null && !empty($match) && array_values($match)[0] !== null) {
    $url = array_values($match)[0];

    //      $this->previewGenerator->generatePreview($url);
    $response = new AjaxResponse();
    $response
      ->addCommand(new ClientCommand($url[0]));
    return $response;
  }
  return null;
}