nortmas
4/10/2018 - 8:01 AM

Integrate entity profile form to any form

<?php

function my_form(&$form, FormStateInterface &$form_state) {
  
  $user = \Drupal::currentUser();

  /** @var \Drupal\profile\ProfileStorageInterface $profile_storage */
  $profile_storage = \Drupal::entityTypeManager()->getStorage('profile');
  
  $profile_ci = $profile_storage->loadByUser($user, 'ci', TRUE);
  
  $form_state->set('form_display_ci', EntityFormDisplay::collectRenderDisplay($profile_ci, 'default'));
  
  $form['entity_ci'] = [
    '#type' => 'details',
    '#title' => 'ci',
    '#tree' => TRUE,
    '#parents' => ['entity_ci'],
  ];
  
  $form_state->get('form_display_ci')->buildForm($profile_ci, $form['entity_ci'], $form_state);

}