Pull merge.
[yaffs-website] / web / core / modules / system / tests / themes / test_theme_settings / theme-settings.php
1 <?php
2
3 /**
4  * @file
5  * Test to ensure theme compatibility with managed files.
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\file\Entity\File;
10
11 /**
12  * Implements hook_form_system_theme_settings_alter().
13  */
14 function test_theme_settings_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
15   $form['custom_logo'] = [
16     '#type' => 'managed_file',
17     '#title' => t('Secondary logo.'),
18     '#default_value' => theme_get_setting('custom_logo'),
19     '#progress_indicator' => 'bar',
20     '#progress_message'   => t('Please wait...'),
21     '#upload_location' => 'public://test',
22     '#upload_validators'  => [
23       'file_validate_extensions' => ['gif png jpg jpeg'],
24     ],
25   ];
26
27   $form['multi_file'] = [
28     '#type' => 'managed_file',
29     '#title' => t('Multiple file field with all file extensions'),
30     '#multiple' => TRUE,
31     '#default_value' => theme_get_setting('multi_file'),
32     '#upload_location' => 'public://test',
33     '#upload_validators'  => [
34       'file_validate_extensions' => [],
35     ],
36   ];
37
38   $form['#submit'][] = 'test_theme_settings_form_system_theme_settings_submit';
39 }
40
41 /**
42  * Test theme form settings submission handler.
43  */
44 function test_theme_settings_form_system_theme_settings_submit(&$form, FormStateInterface $form_state) {
45   if ($file_id = $form_state->getValue(['custom_logo', '0'])) {
46     $file = File::load($file_id);
47     $file->setPermanent();
48     $file->save();
49   }
50 }