Score:1

How to add the title with a sequence number to inline entity form?

ng flag

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.

No Sssweat avatar
ua flag
`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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.