function content_translation_test_form_node_form_alter
Same name in other branches
- 8.9.x core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.module \content_translation_test_form_node_form_alter()
- 10 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
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';
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.