function ContentTranslationTestHooks::formNodeFormAlter
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/ src/ Hook/ ContentTranslationTestHooks.php, line 54
Class
- ContentTranslationTestHooks
- Hook implementations for content_translation_test.
Namespace
Drupal\content_translation_test\HookCode
public function formNodeFormAlter(&$form, FormStateInterface $form_state, $form_id) : void {
$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.