You are here

function content_translation_test_form_node_form_alter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module \content_translation_test_form_node_form_alter()
  2. 9 core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module \content_translation_test_form_node_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

Adds a textfield to node forms based on a request parameter.

File

core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module, line 47
Helper module for the Content Translation tests.

Code

function content_translation_test_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $langcode = $form_state
    ->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';
      }
    }
  }
}