getSenderName example

public function sendMailMessages(MessageInterface $message, AccountInterface $sender) {
    // Clone the sender, as we make changes to mail and name properties.     $sender_cloned = clone $this->userStorage->load($sender->id());
    $params = [];
    $current_langcode = $this->languageManager->getCurrentLanguage()->getId();
    $recipient_langcode = $this->languageManager->getDefaultLanguage()->getId();
    $contact_form = $message->getContactForm();

    if ($sender_cloned->isAnonymous()) {
      // At this point, $sender contains an anonymous user, so we need to take       // over the submitted form values.       $sender_cloned->name = $message->getSenderName();
      $sender_cloned->mail = $message->getSenderMail();

      // For the email message, clarify that the sender name is not verified; it       // could potentially clash with a username on this site.       $sender_cloned->name = $this->t('@name (not verified)', ['@name' => $message->getSenderName()]);
    }

    // Build email parameters.     $params['contact_message'] = $message;
    $params['sender'] = $sender_cloned;

    


  /** * Tests some of the methods. */
  public function testMessageMethods() {
    $message_storage = $this->container->get('entity_type.manager')->getStorage('contact_message');
    $message = $message_storage->create(['contact_form' => 'feedback']);

    // Check for empty values first.     $this->assertEquals('', $message->getMessage());
    $this->assertEquals('', $message->getSenderName());
    $this->assertEquals('', $message->getSenderMail());
    $this->assertFalse($message->copySender());

    // Check for default values.     $this->assertEquals('feedback', $message->getContactForm()->id());
    $this->assertFalse($message->isPersonal());

    // Set some values and check for them afterwards.     $message->setMessage('welcome_message');
    $message->setSenderName('sender_name');
    $message->setSenderMail('sender_mail');
    
$this->drupalGet('contact');
    $this->assertSession()->pageTextContains('Your email address');
    $this->assertSession()->pageTextNotContains('Form');
    $this->submitContact($name = $this->randomMachineName(16)$mail$subject = $this->randomMachineName(16)$id$message = $this->randomMachineName(64));
    $this->assertSession()->pageTextContains('Your message has been sent.');

    $messages = Message::loadMultiple();
    /** @var \Drupal\contact\Entity\Message $message */
    $message = reset($messages);
    $this->assertEquals($id$message->getContactForm()->id());
    $this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
    $this->assertEquals($name$message->getSenderName());
    $this->assertEquals($subject$message->getSubject());
    $this->assertEquals($mail$message->getSenderMail());

    $config = $this->config("contact.form.$id");
    $this->assertEquals($id$config->get('id'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.