You are here

public function ContactFormBlock::build in Form Block 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Block/ContactFormBlock.php \Drupal\formblock\Plugin\Block\ContactFormBlock::build()

Implements \Drupal\block\BlockBase::build().

Overrides BlockPluginInterface::build

File

src/Plugin/Block/ContactFormBlock.php, line 180

Class

ContactFormBlock
Provides a block for contact form.

Namespace

Drupal\formblock\Plugin\Block

Code

public function build() {
  $build = [];

  // Check if flood control has been activated for sending emails.
  if (!$this->currentUser
    ->hasPermission('administer contact forms') && ($message = $this
    ->floodControl())) {
    $build['message'] = [
      '#markup' => $message,
    ];
    return $build;
  }
  $message = $this->entityTypeManager
    ->getStorage('contact_message')
    ->create([
    'contact_form' => $this
      ->getContactForm()
      ->id(),
  ]);
  $build['form'] = $this->entityFormBuilder
    ->getForm($message);
  return $build;
}