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:
But I need to display the sequence number of this design next to the word Design:
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:
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.