theme-settings.php

Same filename in other branches
  1. 7.x themes/garland/theme-settings.php
  2. 7.x modules/simpletest/tests/themes/test_theme/theme-settings.php
  3. 9 core/themes/olivero/theme-settings.php
  4. 9 core/modules/system/tests/themes/test_theme_settings/theme-settings.php
  5. 10 core/themes/olivero/theme-settings.php
  6. 10 core/modules/system/tests/themes/test_theme_settings/theme-settings.php
  7. 11.x core/themes/olivero/theme-settings.php
  8. 11.x core/modules/system/tests/themes/test_theme_settings/theme-settings.php

Test to ensure theme compatibility with managed files.

File

core/modules/system/tests/themes/test_theme_settings/theme-settings.php

View source
<?php


/**
 * @file
 * Test to ensure theme compatibility with managed files.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;

/**
 * Implements hook_form_system_theme_settings_alter().
 */
function test_theme_settings_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
    $form['custom_logo'] = [
        '#type' => 'managed_file',
        '#title' => t('Secondary logo.'),
        '#default_value' => theme_get_setting('custom_logo'),
        '#progress_indicator' => 'bar',
        '#progress_message' => t('Please wait...'),
        '#upload_location' => 'public://test',
        '#upload_validators' => [
            'file_validate_extensions' => [
                'gif png jpg jpeg',
            ],
        ],
    ];
    $form['multi_file'] = [
        '#type' => 'managed_file',
        '#title' => t('Multiple file field with all file extensions'),
        '#multiple' => TRUE,
        '#default_value' => theme_get_setting('multi_file'),
        '#upload_location' => 'public://test',
        '#upload_validators' => [
            'file_validate_extensions' => [],
        ],
    ];
    $form['#submit'][] = 'test_theme_settings_form_system_theme_settings_submit';
}

/**
 * Test theme form settings submission handler.
 */
function test_theme_settings_form_system_theme_settings_submit(&$form, FormStateInterface $form_state) {
    if ($file_id = $form_state->getValue([
        'custom_logo',
        '0',
    ])) {
        $file = File::load($file_id);
        $file->setPermanent();
        $file->save();
    }
}

Functions

Title Deprecated Summary
test_theme_settings_form_system_theme_settings_alter Implements hook_form_system_theme_settings_alter().
test_theme_settings_form_system_theme_settings_submit Test theme form settings submission handler.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.