Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / content_translation / tests / modules / content_translation_test / content_translation_test.module
1 <?php
2
3 /**
4  * @file
5  * Helper module for the Content Translation tests.
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9
10 /**
11  * Implements hook_form_BASE_FORM_ID_alter().
12  *
13  * Adds a textfield to node forms based on a request parameter.
14  */
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',
21     ];
22
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';
26       }
27     }
28   }
29 }
30
31 /**
32  * Form submission handler for custom field added based on a request parameter.
33  *
34  * @see content_translation_test_form_node_article_form_alter()
35  */
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'));
38 }