getReply example

// Send email to the recipient(s).     $key_prefix = $message->isPersonal() ? 'user' : 'page';
    $this->mailManager->mail('contact', $key_prefix . '_mail', $to$recipient_langcode$params$sender_cloned->getEmail());

    // If requested, send a copy to the user, using the current language.     if ($message->copySender()) {
      $this->mailManager->mail('contact', $key_prefix . '_copy', $sender_cloned->getEmail()$current_langcode$params$sender_cloned->getEmail());
    }

    // If configured, send an auto-reply, using the current language.     if (!$message->isPersonal() && $contact_form->getReply()) {
      // User contact forms do not support an auto-reply message, so this       // message always originates from the site.       if (!$sender_cloned->getEmail()) {
        $this->logger->error('Error sending auto-reply, missing sender e-mail address in %contact_form', [
          '%contact_form' => $contact_form->label(),
        ]);
      }
      else {
        $this->mailManager->mail('contact', 'page_autoreply', $sender_cloned->getEmail()$current_langcode$params);
      }
    }

    

  protected function assertEntity(string $id, string $expected_label, array $expected_recipients, string $expected_reply, int $expected_weight): void {
    /** @var \Drupal\contact\ContactFormInterface $entity */
    $entity = ContactForm::load($id);
    $this->assertInstanceOf(ContactFormInterface::class$entity);
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_recipients$entity->getRecipients());
    $this->assertSame($expected_reply$entity->getReply());
    $this->assertSame($expected_weight$entity->getWeight());
  }

  /** * The Drupal 6 and 7 contact categories to Drupal 8 migration. */
  public function testContactCategory() {
    $this->assertEntity('website_feedback', 'Website feedback', ['admin@example.com'], '', 0);
    $this->assertEntity('some_other_category', 'Some other category', ['test@example.com'], 'Thanks for contacting us, we will reply ASAP!', 1);
    $this->assertEntity('a_category_much_longer_than_th', 'A category much longer than thirty two characters', ['fortyninechars@example.com'], '', 2);

    

    $form['redirect'] = [
      '#type' => 'path',
      '#title' => $this->t('Redirect path'),
      '#convert_path' => PathElement::CONVERT_NONE,
      '#default_value' => $contact_form->getRedirectPath(),
      '#description' => $this->t('Path to redirect the user to after submission of this form. For example, type "/about" to redirect to that page. Use a relative path with a slash in front.'),
    ];
    $form['reply'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Auto-reply'),
      '#default_value' => $contact_form->getReply(),
      '#description' => $this->t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
    ];
    $form['weight'] = [
      '#type' => 'weight',
      '#title' => $this->t('Weight'),
      '#default_value' => $contact_form->getWeight(),
      '#description' => $this->t('When listing forms, those with lighter (smaller) weights get listed before forms with heavier (larger) weights. Forms with equal weights are sorted alphabetically.'),
    ];
    $form['selected'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Make this the default form'),
      
Home | Imprint | This part of the site doesn't use cookies.