1

I have an edit form of a custom entity that is passed to the controller:
$form = $this->entityFormBuilder()->getForm($entity_quote, 'edit');

This custom entity has the reference field to another custom entity quote_design. Widget for this field - Inline entity form - Complex.

I added this code to display the word Design above each inline entity form:

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function entity_quotes_inline_entity_form_entity_form_alter(&$entity_form, FormStateInterface $form_state) {

  $form_bundles = [
    'quote_design',
  ];

 if ($entity_form['#bundle'] == 'quote_design') {
   $entity_form['dummy_design_header_title'] = [
     '#type' => 'html_tag',
     '#tag' => 'h3',
     '#value' => 'Design',
     '#attributes' => [
       'class' => ['dummy'],
     ],
   ];
 }

}

And now I see the word Design above every Inline form:

enter image description here

But I need to display the sequence number of this design next to the word Design:

enter image description here

How to implement it?


I tried like this:

$created_designs = $form_state->getFormObject()->getEntity()->get('field_design')->getValue();

foreach ($created_designs as $key => $value) {
  $entity_form['dummy_design_header_title_' . $key] = [
    '#type' => 'html_tag',
    '#weight' => -100,
    '#tag' => 'h3',
    '#value' => 'Design ' . ($key + 1),
    '#attributes' => [
      'class' => ['dummy'],
    ],
  ];
}


But then I get the first problem:

enter image description here

And I get the second problem:

When I get the inline forms in this way:
$form_state->getFormObject()->getEntity()->get('field_design')->getValue();
I get only the saved inline forms, but the new inline forms added with the Add another Design button is not there. I need to display the title with a sequence number for both saved and new ones not yet saved.

1
  • 2
    but the new inline forms added with the Add another Design button is not there. form_alters do not have any effect on with AJAX. The only way is to do the modification through the ajax callback function.
    – No Sssweat
    May 25 at 5:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.