I have call my current contactform with this function in mytheme.theme.

$form = Drupal::routeMatch()->getParameter('contact_form');

I have this

object(Drupal\contact\Entity\ContactForm)#412 (23) {
  string(8) "feedback"
  string(14) "Nous contacter"
  array(1) {
    string(21) "[email protected]"
  string(0) ""
  string(8) "feedback"
  string(36) "6e997e8b-9d85-4e59-9e43-67004270fe13"
  string(2) "fr"
  array(0) {
  array(0) {
  string(12) "contact_form"
  array(1) {
    string(28) "languages:language_interface"
  array(0) {
  array(0) {
  array(0) {

But how can I rendering this ? My goal is to render the current contact form.

Edit1: I have tried this How to programmatically render a contact form in a theme in D8

But when I try this

    $form = Drupal::routeMatch()->getParameter('contact_form');//get the current form called
    $message = \Drupal::entityManager()
        'contact_form' => $form->id(),
//$form->id() = 'feedback'
        $form = Drupal::service('entity.form_builder')->getForm($message);

I have a very big array (Firefox and Chrome crash when in print them )

When I try this

$form = Drupal::routeMatch()->getParameter('contact_form');//get the current form called

I have this error

PHP Fatal error: Call to a member function getStorage() on null in /var/www/drupal8/core/modules/contact/src/Controller/ContactController.php on line 83

Why I would like to do this in my .theme file ?

Because I have begin to migrate a website in drupal 6 to drupal 8 .(I have try Drupal Upgrate and they works very good ) The page of this website has been built with a little home framework. It call many others not Drupal script. With this, not Drupal Script (Ex:tagada.com/horoscope.php ) and drupal page ( tagada.com/drupalpart/node/10) works with same css and html structure file in a external folder. In Drupal6 the theme worked correctly with a global variable object with node content $node

  • Have you try it out drupal_render ? I do not know if that works or not. Jan 18, 2016 at 7:44
  • Rendering is not the problem, you need to get the build array of the form, see drupal.stackexchange.com/questions/146617/…
    – 4uk4
    Jan 18, 2016 at 7:58
  • Welcome to Drupal Answers! I am sorry, but you need to provide more details, to ask a question. A single line of code, without knowing where you are using it, is not a question. Also, in general themes don't use code like that.
    – apaderno
    Jan 18, 2016 at 11:49
  • With contact_storage module, you can use an entity reference field to render it
    – larowlan
    Jan 18, 2016 at 12:40
  • @kiamlaluno Tank's for your answer I have write more details in Edit1
    – Agriesean
    Jan 18, 2016 at 13:13

1 Answer 1


Finnaly I have find the answer to my problem's .

It was a drupal permission problem's .

User Anonymous users do not have permission to use the general contact form. I gave permission and everything worked .

Thank you alot for the advice .


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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