class TestThemeThemeHooks

Hook implementations for test_theme_theme.

Hierarchy

Expanded class hierarchy of TestThemeThemeHooks

File

core/modules/system/tests/themes/test_theme_theme/src/Hook/TestThemeThemeHooks.php, line 16

Namespace

Drupal\test_theme_theme\Hook
View source
class TestThemeThemeHooks {
  use StringTranslationTrait;
  public function __construct(protected EntityTypeManagerInterface $entityTypeManager, protected ThemeSettingsProvider $themeSettingsProvider) {
  }
  
  /**
   * Implements hook_form_system_theme_settings_alter().
   */
  public function formSystemThemeSettingsAlter(&$form, FormStateInterface $form_state) : void {
    $form['custom_logo'] = [
      '#type' => 'managed_file',
      '#title' => $this->t('Secondary logo.'),
      '#default_value' => $this->themeSettingsProvider
        ->getSetting('custom_logo'),
      '#progress_indicator' => 'bar',
      '#progress_message' => $this->t('Processing...'),
      '#upload_location' => 'public://test',
      '#upload_validators' => [
        'FileExtension' => [
          'extensions' => 'gif png jpg jpeg',
        ],
      ],
    ];
    $form['#submit'][] = static::class . ':themeSettingsSubmit';
  }
  
  /**
   * Test theme form settings submission handler.
   */
  public function themeSettingsSubmit(&$form, FormStateInterface $form_state) : void {
    if ($file_id = $form_state->getValue([
      'custom_logo',
      '0',
    ])) {
      /** @var Drupal\file\Entity\FileInterface $file */
      $file = $this->entityTypeManager
        ->getStorage('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
TestThemeThemeHooks::formSystemThemeSettingsAlter public function Implements hook_form_system_theme_settings_alter().
TestThemeThemeHooks::themeSettingsSubmit public function Test theme form settings submission handler.
TestThemeThemeHooks::__construct public function

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