sendMailMessages example

/** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $message = $this->entity;
    $user = $this->currentUser();
    // Save the message. In core this is a no-op but should contrib wish to     // implement message storage, this will make the task of swapping in a real     // storage controller straight-forward.     $message->save();
    $this->mailHandler->sendMailMessages($message$user);
    $contact_form = $message->getContactForm();

    $this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
    if ($submission_message = $contact_form->getMessage()) {
      $this->messenger()->addStatus($submission_message);
    }

    // To avoid false error messages caused by flood control, redirect away from     // the contact form; either to the contacted user account or the front page.     if ($message->isPersonal() && $user->hasPermission('access user profiles')) {
      $form_state->setRedirectUrl($message->getPersonalRecipient()->toUrl());
    }
->method('load')
      ->willReturn($sender);
    // User IDs 1 and 0 have special implications, use 3 instead.     $sender->expects($this->any())
      ->method('id')
      ->willReturn(3);
    $sender->expects($this->once())
      ->method('isAnonymous')
      ->willReturn(FALSE);
    $this->expectException(MailHandlerException::class);
    $this->expectExceptionMessage('Unable to determine message recipient');
    $this->contactMailHandler->sendMailMessages($message$sender);
  }

  /** * Tests the sendMailMessages method. * * @dataProvider getSendMailMessages * * @covers ::sendMailMessages */
  public function testSendMailMessages(MessageInterface $message, AccountInterface $sender$results) {
    $this->logger->expects($this->once())
      
Home | Imprint | This part of the site doesn't use cookies.