As you already imply in your question, you'll want to use a custom controller action that returns the form depending on your node type.
First, alter the route to point to a controller method:
my_node_action.go:
path: '/node/{node}/go'
defaults:
_title_callback: '\Drupal\my_node_action\Controller\GoController::goFormTitle'
_controller: '\Drupal\my_node_action\Controller\GoController::goForm'
options:
parameters:
node:
type: entity:node
requirements:
_user_is_logged_in: 'TRUE'
Then you create the GoController.php
file in your module's src/Controller
folder:
<?php
namespace Drupal\my_node_action\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GoController extends ControllerBase implements ContainerInjectionInterface {
/**
* Constructs a GoController instance.
*
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(
FormBuilderInterface $form_builder
) {
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('form_builder')
);
}
/**
* Return the go form.
*
* @param \Drupal\node\NodeInterface $node
* The node.
*
* @return array
* Form render array for the go form.
*/
public function goForm(NodeInterface $node) {
$form = [];
switch ($node->getType()) {
case 'type1':
$form = $this->formBuilder()->getForm('Drupal\my_node_action\Form\NodeType1Go', $node);
break;
// Further types/forms and/or a default form here...
}
return $form;
}
/**
* Return the go form title.
*
* @param \Drupal\node\NodeInterface $node
* The node.
*
* @return string
* Form title.
*/
public function goFormTitle(NodeInterface $node) {
// Whatever logic may apply here...
}
}