getFormObject()->getFormLangcode($form_state); if (in_array($langcode, ['en', 'fr']) && \Drupal::request()->get('test_field_only_en_fr')) { $form['test_field_only_en_fr'] = [ '#type' => 'textfield', '#title' => 'Field only available on the english and french form', ]; foreach (array_keys($form['actions']) as $action) { if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { $form['actions'][$action]['#submit'][] = 'content_translation_test_form_node_form_submit'; } } } } /** * Form submission handler for custom field added based on a request parameter. * * @see content_translation_test_form_node_article_form_alter() */ function content_translation_test_form_node_form_submit($form, FormStateInterface $form_state) { \Drupal::state()->set('test_field_only_en_fr', $form_state->getValue('test_field_only_en_fr')); }