You are here

public function ContactController::content in Email Contact 8

1 string reference to 'ContactController::content'
email_contact.routing.yml in ./email_contact.routing.yml
email_contact.routing.yml

File

src/Controller/ContactController.php, line 31

Class

ContactController
Class ContactController.

Namespace

Drupal\email_contact\Controller

Code

public function content($entity_type = NULL, $entity_id = NULL, $field_name = NULL, $view_mode = 'full') {
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->load($entity_id);
  $view_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
  $field_display = $view_display
    ->getComponent($field_name);
  $field_settings = $field_display['settings'];
  try {
    $form = new ContactForm($entity_type, $entity_id, $field_name, $field_settings);
    return \Drupal::formBuilder()
      ->getForm($form);
  } catch (NotFoundHttpException $e) {
    \Drupal::logger('email_contact')
      ->notice('Invalid contact form on @entity_type id @id.', [
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '@id' => $entity
        ->id(),
    ]);
  }
}