I'm loading a field collection item form inside of a formatter. Below is the function loading the form, which works. However I do not want to call the normal field collection submitForm handler, I want to override the submit handler with my own. I've tried attaching my submit handler, but the field collection submit handler still continues getting called.
I don't want to use a form_alter, I'm trying to keep this in the FormBase or ContentEntityForm class. Does anyone know how I can override the field collection submit handler?
<?php
public function getFCForm(FieldItemInterface $item, $fc_name) {
$entity = $item->getFieldCollectionItem();
$displays = EntityViewDisplay::collectRenderDisplays([$entity], 'full');
$display = $displays[$entity->bundle()];
foreach ($display->getComponents() as $name => $options) {
$fields_by_weight[$options['weight']] = $name;
}
ksort($fields_by_weight);
//load fc entity
$fieldCollection = \Drupal\field_collection\Entity\FieldCollection::load($fc_name);
$field_collection_item = \Drupal::entityTypeManager()
->getStorage('field_collection_item')
->create([
'field_name' => $fieldCollection->id(),
'host_type' => 'node',
'revision_id' => 0,
]);
$form = \Drupal::service('entity.form_builder')->getForm($field_collection_item);
$form['#prefix'] = '<div id="inline_fc_form">';
$form['#suffix'] = '</div>';
$form['actions']['submit']['#submit']=['::ajaxFormSubmitHandler'];
$form['actions']['submit']['#ajax_processed'] = TRUE;
$form['actions']['submit']['#value'] = t('wtf');
$form['#validate'] = ['::validateForm'];
$form['#submit'] = ['::ajaxFormSubmitHandler'];
//custom submit handler not being called?
return $form;
}