937494f10138e18a81354320022f2d896d7a75cf
[yaffs-website] / web / core / modules / system / tests / themes / test_theme_theme / test_theme_theme.theme
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_theme_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
15
16   $form['custom_logo'] = [
17     '#type' => 'managed_file',
18     '#title' => t('Secondary logo.'),
19     '#default_value' => theme_get_setting('custom_logo'),
20     '#progress_indicator' => 'bar',
21     '#progress_message'   => t('Please wait...'),
22     '#upload_location' => 'public://test',
23     '#upload_validators'  => [
24       'file_validate_extensions' => ['gif png jpg jpeg'],
25     ],
26   ];
27
28   $form['#submit'][] = 'test_theme_theme_form_system_theme_settings_submit';
29 }
30
31 /**
32  * Test theme form settings submission handler.
33  */
34 function test_theme_theme_form_system_theme_settings_submit(&$form, FormStateInterface $form_state) {
35   if ($file_id = $form_state->getValue(['custom_logo', '0'])) {
36     $file = File::load($file_id);
37     $file->setPermanent();
38     $file->save();
39   }
40 }