The documentation states:

The argument passed to the getForm() method is the name of the class that defines your form and is an implementation of \Drupal\Core\Form\FormBuilderInterface.

How do I find out the name of the class that defines the website feedback form provided by the core contact module (the form id is: feedback_contact_message_form).

When I dpm() the form I can see that there is a class defined:

$input array(30)
  →'#attributes' => array(1)
    →'class' => array(3)
      string(29) "feedback-contact-message-form"
      string(20) "contact-message-form"
      string(12) "contact-form"

I tried various forms of this as the parameter to pass to:


but no luck. Thanks

  • 1
    Contact forms are entities, so I'd imagine they all come from Drupal\contact\ContactFormEditForm. Not sure there's an easy way to find that out unless you know it's an entity form though. The best way might be to look under the module's src folder for files whose name ends with Form.php. I think that's a safe convention to follow
    – Clive
    Feb 10 '15 at 17:45
  • Wouldn't Berdir's answer in my question help? drupal.stackexchange.com/questions/146617/…
    – alexej_d
    Feb 11 '15 at 9:15
  • Thanks, but I don't follow Berdir's answer. I've added my block plugin below my answer - adding the first two lines from your code sample. Where do I go from here? Thanks.
    – dbj44
    Feb 11 '15 at 10:03

This renders within a block plugin:

class myModule extends BlockBase {
  public function build() {

    $default_form = \Drupal::config('contact.settings')->get('default_form');
    $entity = \Drupal::entityManager()->getStorage('contact_form')->load($default_form);

    $message = \Drupal::entityManager()
        'contact_form' => $entity->id(),

    $form = \Drupal::service('entity.form_builder')->getForm($message);

    return $form;
  • I'm having the same issue. can we share notes and chat? All I want to do is just take a form from somwhere on the site and output it somewhere else inside a PHP enabled text field. Jul 28 '16 at 21:51
  • How I can submit this entity form programatically? Aug 29 '16 at 6:35
  • if the form needs to act on #after_build, for ajax operation, do we have any solution? Jun 16 '17 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.