Problem/Motivation

The contact module currently lets us only use a separate page to display the contact forms. In my use case this is not suited since I want to display a node on the same page.

So I tried to create the block and get the from like this:

<?php
$message = \Drupal::entityManager()->getStorage('contact_message')
  ->create(array(
    'category' => 'feedback',
));

$form = \Drupal\contact\Controller\ContactController::contactSitePage();
?>

But this throws an error:

Fatal error: Call to undefined method Drupal\attribute_project\Plugin\Block\ContactFormBlock::currentUser()

How could this be accomplished by code?

Proposed resolution

Provide blocks for contact categories.

Remaining tasks

  • Provide blocks for contact categories

User interface changes

Maybe provide checkboxes to enable a block for contact categories?

API changes

Make it easier to get the forms?

Comments

Lukas von Blarer’s picture

Issue summary: View changes
Lukas von Blarer’s picture

Issue summary: View changes
Lukas von Blarer’s picture

Issue summary: View changes
Hydra’s picture

You need to get the Form form the entity form builder

$message = \Drupal::entityManager()
  ->getStorage('contact_message')
  ->create(array(
    'contact_form' => 'feedback',
  ));
$form = \Drupal::service('entity.form_builder')->getForm($message);

Not sure if there will be a solution in Core for that.
A nice place could be in contrib like https://www.drupal.org/project/contact_form_blocks

Lukas von Blarer’s picture

Ok, I will try this.

Makes sense to provide this as a contrib module. Should we mark this as wont fix?

larowlan’s picture

Version: 8.0.x-dev » 8.1.x-dev

Lets leave this as a feature request

andypost’s picture

Status: Active » Closed (duplicate)
Related issues: +#1997692: Create contact form block