I have a custom entity, that is depending on the user entity. In fact, it is even so depending that I felt it made sense to display my entity form within the user profile form:
The problem I am now having is the following; there are 2 save buttons. And if it is not bad enough, the save button for the user (the lower one) does not even function anymore and white label save button only saves the white label entity.
The form is altered into the user form like this:
function whitelabel_form_user_form_alter(&$form, FormStateInterface $form_state) {
$whitelabel = WhiteLabel::load(1);
$whitelabel_form = \Drupal::service('entity.manager')
->getFormObject('whitelabel', 'default')
->setEntity($whitelabel);
$form['whitelabel'] = array(
'#type' => 'details',
'#title' => t('White label settings'),
'#open' => TRUE,
'form' => \Drupal::formBuilder()->getForm($whitelabel_form),
);
}
I was hoping to shuffle some parameters in the $whitelabel_form
array (that used to work in Drupal 7), but that array is enormous and I could not find the submit buttons and handler that I needed.
So the question is, can this be done? And what would be the recommended way of doing it?