5 * Helper module for the Content Translation tests.
8 use Drupal\Core\Form\FormStateInterface;
11 * Implements hook_form_BASE_FORM_ID_alter().
13 * Adds a textfield to node forms based on a request parameter.
15 function content_translation_test_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
16 $langcode = $form_state->getFormObject()->getFormLangcode($form_state);
17 if (in_array($langcode, ['en', 'fr']) && \Drupal::request()->get('test_field_only_en_fr')) {
18 $form['test_field_only_en_fr'] = [
19 '#type' => 'textfield',
20 '#title' => 'Field only available on the english and french form',
23 foreach (array_keys($form['actions']) as $action) {
24 if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
25 $form['actions'][$action]['#submit'][] = 'content_translation_test_form_node_form_submit';
32 * Form submission handler for custom field added based on a request parameter.
34 * @see content_translation_test_form_node_article_form_alter()
36 function content_translation_test_form_node_form_submit($form, FormStateInterface $form_state) {
37 \Drupal::state()->set('test_field_only_en_fr', $form_state->getValue('test_field_only_en_fr'));