Update the .routing.yml
file like so:
test.check-test:
path: 'node/{node}/test'
defaults:
_form: '\Drupal\test\Form\Test'
_title: 'Test'
requirements:
_permission: 'access test'
node: \d+
options:
_node_operation_route: TRUE
Then use it in your form controller the following way:
namespace Drupal\test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
class Test extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
$form['placeholder'] = [
'#markup' => t('This is the form for @node_title.', [
'@node_title' => $node->getTitle(),
]),
];
return $form;
}
}