Using Drupal 8.5.3. Currently working within a custom controller to load and alter a form for menu links. To load the form I am using the following:
// Load the menu link field.
$menu_link_content = MenuLinkContent::create([
'title' => 'Example link',
'link' => ['uri' => 'internal:/node'],
'menu_name' => 'main',
]);
$form = \Drupal::service('entity.form_builder')->getForm($menu_link_content, 'default', $form_state_params);
Simple enough right? From there I go onwards to alter $form inside the same method in the controller. I can change the $form values from there to adjust which menu items are available.
The problem is that I can't seem to add a submit handler.
I've tried both of these to add a submit handler, to no avail.
$form['#submit'][] = 'group_content_submenu_group_link_add_submit';
$form['actions']['submit']['#submit'][] = 'group_content_submenu_group_link_add_submit';
Any ideas on what I could be missing? I'm open to other approaches as well, but I specifically need to be able to set the parent item that this form should be using to present available parent menu link choices.