8 – How to get parent node values on inline entity form hook alter?


I am using inline entity forms to create a paragraph in a node form. When I add a node I want the title of the node form to be copied to the paragraph when I click on “Add paragraph”. I use hook_inline_entity_form_entity_form_alter to prefill the title field. That works, only I can’t get the values from the node form. Not with the below code.

function example_forms_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  $node = $form_state->getFormObject()->getEntity();
  if ($node->getType() == "task" && $entity_form('#bundle') == "improvement") {
    Drupal::logger('Form state values')->debug("<pre>" . print_r($form_state->getValues(), TRUE) . "</pre>");
    Drupal::logger('Node values')->debug("<pre>" . print_r($node, TRUE) . "</pre>");
    $entity_form('title')('widget')(0)('value')('#default_value') = 'This is Jessica';
  }
}

Can someone help me solve this?