config('contact.settings'); // Use the default form if no form has been passed. $manager = $this->entityTypeManager(); if (empty($contact_form)) { $contact_form = $manager ->getStorage('contact_form') ->load($config->get('default_form')); // If there are no forms, do not display the form. if (empty($contact_form)) { if ($this->currentUser()->hasPermission('administer contact forms')) { $this->messenger()->addError($this->t('The contact form has not been configured. Add one or more forms .', [ ':add' => Url::fromRoute('contact.form_add')->toString(), ])); return []; } else { throw new NotFoundHttpException(); } } } $view_builder = $manager->getViewBuilder('contact_form'); return $view_builder->view($contact_form, 'full', $contact_form->language()); } /** * Route title callback. * * @param \Drupal\contact\ContactFormInterface $contact_form * The contact form. * * @return string * The title of the contact form. */ public function contactFormTitle(ContactFormInterface $contact_form) { return $contact_form->label(); } /** * Edit route title callback. * * @param \Drupal\contact\ContactFormInterface $contact_form * The contact form. * * @return string * The title of the contact form. */ public function contactEditFormTitle(ContactFormInterface $contact_form) { return $this->t('Edit @label', ['@label' => $contact_form->label()]); } }