You are here

function PetPreviewForm::pet_callback_recipients in Previewable email templates 8

Same name and namespace in other branches
  1. 8.4 src/Form/PetPreviewForm.php \Drupal\pet\Form\PetPreviewForm::pet_callback_recipients()

Return an array of email recipients provided by a callback function.

File

src/Form/PetPreviewForm.php, line 354

Class

PetPreviewForm

Namespace

Drupal\pet\Form

Code

function pet_callback_recipients(FormStateInterface $form_state) {
  $callback = $form_state
    ->getValue('recipient_callback');
  if (!empty($callback)) {
    if (function_exists($callback)) {
      $recipients = $callback();

      // Remove uid for backward compatibility
      if (isset($recipients) && is_array($recipients)) {
        $new_recipients = [];
        foreach ($recipients as $recipient) {
          $recipient = preg_replace('/^[0-9]*\\|/', '', $recipient);
          $new_recipients[] = $recipient;
        }
        return $new_recipients;
      }
    }
  }
  return NULL;
}