1

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) {
  ["id":protected]=>
  string(8) "feedback"
  ["label":protected]=>
  string(14) "Nous contacter"
  ["recipients":protected]=>
  array(1) {
    [0]=>
    string(21) "mymail@gmail.com"
  }
  ["reply":protected]=>
  string(0) ""
  ["weight":protected]=>
  int(0)
  ["originalId":protected]=>
  string(8) "feedback"
  ["pluginConfigKey":protected]=>
  NULL
  ["status":protected]=>
  bool(true)
  ["uuid":protected]=>
  string(36) "6e997e8b-9d85-4e59-9e43-67004270fe13"
  ["isSyncing":"Drupal\Core\Config\Entity\ConfigEntityBase":private]=>
  bool(false)
  ["isUninstalling":"Drupal\Core\Config\Entity\ConfigEntityBase":private]=>
  bool(false)
  ["langcode":protected]=>
  string(2) "fr"
  ["third_party_settings":protected]=>
  array(0) {
  }
  ["_core":protected]=>
  array(0) {
  }
  ["trustedData":protected]=>
  bool(false)
  ["entityTypeId":protected]=>
  string(12) "contact_form"
  ["enforceIsNew":protected]=>
  NULL
  ["typedData":protected]=>
  NULL
  ["cacheContexts":protected]=>
  array(1) {
    [0]=>
    string(28) "languages:language_interface"
  }
  ["cacheTags":protected]=>
  array(0) {
  }
  ["cacheMaxAge":protected]=>
  int(-1)
  ["_serviceIds":protected]=>
  array(0) {
  }
  ["dependencies":protected]=>
  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()
      ->getStorage('contact_message')
      ->create(array(
        '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
ContactController::contactSitePage($form);

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. – darol100 Jan 18 '16 at 7:44
  • Rendering is not the problem, you need to get the build array of the form, see drupal.stackexchange.com/questions/146617/… – 4k4 Jan 18 '16 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. – kiamlaluno Jan 18 '16 at 11:49
  • With contact_storage module, you can use an entity reference field to render it – larowlan Jan 18 '16 at 12:40
  • @kiamlaluno Tank's for your answer I have write more details in Edit1 – Agriesean Jan 18 '16 at 13:13
0

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, privacy policy and cookie policy

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