You are here

protected function ContactBlock::createContactMessage in Contact Block 8

Creates the contact message entity without saving it.

Return value

\Drupal\contact\Entity\Message|null The contact message entity. NULL if the entity does not exist.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to ContactBlock::createContactMessage()
ContactBlock::blockAccess in src/Plugin/Block/ContactBlock.php
Indicates whether the block should be shown.
ContactBlock::build in src/Plugin/Block/ContactBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/ContactBlock.php, line 276

Class

ContactBlock
Provides a 'ContactBlock' block.

Namespace

Drupal\contact_block\Plugin\Block

Code

protected function createContactMessage() {
  $contact_message = NULL;
  $contact_form = $this
    ->getContactForm();
  if ($contact_form) {
    $contact_message = $this->entityTypeManager
      ->getStorage('contact_message')
      ->create([
      'contact_form' => $contact_form
        ->id(),
    ]);
  }
  return $contact_message;
}