class TestThemeSettingsHooks
Hook implementations for test_theme_settings.
Hierarchy
- class \Drupal\test_theme_settings\Hook\TestThemeSettingsHooks uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of TestThemeSettingsHooks
File
-
core/
modules/ system/ tests/ themes/ test_theme_settings/ src/ Hook/ TestThemeSettingsHooks.php, line 16
Namespace
Drupal\test_theme_settings\HookView source
class TestThemeSettingsHooks {
use StringTranslationTrait;
/**
* Implements hook_form_system_theme_settings_alter().
*/
public function formSystemThemeSettingsAlter(array &$form, FormStateInterface $form_state) : void {
/** @var \Drupal\Core\Extension\ThemeSettingsProvider $theme_settings_provider */
$theme_settings_provider = \Drupal::service(ThemeSettingsProvider::class);
$form['custom_logo'] = [
'#type' => 'managed_file',
'#title' => $this->t('Secondary logo.'),
'#default_value' => $theme_settings_provider->getSetting('custom_logo'),
'#progress_indicator' => 'bar',
'#progress_message' => $this->t('Processing...'),
'#upload_location' => 'public://test',
'#upload_validators' => [
'FileExtension' => [
'extensions' => 'gif png jpg jpeg',
],
],
];
$form['multi_file'] = [
'#type' => 'managed_file',
'#title' => $this->t('Multiple file field with all file extensions'),
'#multiple' => TRUE,
'#default_value' => $theme_settings_provider->getSetting('multi_file'),
'#upload_location' => 'public://test',
'#upload_validators' => [
'FileExtension' => [],
],
];
$form['#submit'][] = [
static::class,
'submitForm',
];
}
/**
* Form submission handler for the theme settings form.
*/
public static function submitForm(array &$form, FormStateInterface $form_state) : void {
if ($file_id = $form_state->getValue([
'custom_logo',
'0',
])) {
$file = File::load($file_id);
$file->setPermanent();
$file->save();
}
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 1 |
| TestThemeSettingsHooks::formSystemThemeSettingsAlter | public | function | Implements hook_form_system_theme_settings_alter(). | |
| TestThemeSettingsHooks::submitForm | public static | function | Form submission handler for the theme settings form. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.