diff --git a/core/modules/system/src/Tests/Theme/ThemeTest.php b/core/modules/system/src/Tests/Theme/ThemeTest.php index 4eae7ae..f52b4ba 100644 --- a/core/modules/system/src/Tests/Theme/ThemeTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeTest.php @@ -216,7 +216,7 @@ function testListThemes() { // Check if ThemeHandlerInterface::listInfo() returns disabled themes. // Check for base theme and subtheme lists. $base_theme_list = array('test_basetheme' => 'Theme test base theme'); - $sub_theme_list = array('test_subsubtheme' => 'Theme test subsubtheme', 'test_subtheme' => 'Theme test subtheme'); + $sub_theme_list = array('test_subsubtheme' => 'Theme test subsubtheme', 'test_subtheme' => 'Theme test subtheme', 'test_theme_alter' => 'Theme test alter'); $this->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, 'Base theme\'s object includes list of subthemes.'); $this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, 'Subtheme\'s object includes list of base themes.'); diff --git a/core/modules/system/src/Tests/Theme/ThemeTestCustomSettings.php b/core/modules/system/src/Tests/Theme/ThemeTestCustomSettings.php new file mode 100644 index 0000000..19967cf --- /dev/null +++ b/core/modules/system/src/Tests/Theme/ThemeTestCustomSettings.php @@ -0,0 +1,65 @@ +bigUser = $this->drupalCreateUser(array('administer themes')); + // Install theme. + \Drupal::service('theme_handler')->install(array('test_theme_alter')); + } + + /** + * Tests extend theme settings with custom fields and custom submit handlers. + */ + function testCustomThemeSettings() { + $theme = 'test_theme_alter'; + + $this->config('system.theme') + ->set('default', $theme) + ->save(); + + $settings_path = 'admin/appearance/settings/' . $theme; + + $this->drupalLogin($this->bigUser); + + $this->drupalGet($settings_path); + $this->assertResponse(200); + // Altered fields + $this->assertFieldByName('toggle_favicon', FALSE); + // Custom fields + $this->assertFieldByName('custom_flag', FALSE); + $this->assertFieldByName('custom_text', ''); + $this->assertFieldByName('custom_logo', ''); + + $edit = array( + 'custom_flag' => TRUE, + 'custom_text' => 'Tests text', + 'custom_logo' => 'core/misc/druplicon.png', + ); + $this->drupalPostForm($settings_path, $edit, t('Save configuration')); + $this->assertText('The configuration options have been saved.'); + $this->assertFieldByName('custom_flag', $edit['custom_flag']); + $this->assertFieldByName('custom_text', $edit['custom_text']); + $this->assertFieldByName('custom_logo', $edit['custom_logo']); + } + +} diff --git a/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.info.yml b/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.info.yml new file mode 100644 index 0000000..d718e05 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.info.yml @@ -0,0 +1,6 @@ +name: 'Theme test alter' +type: theme +description: 'Test theme alter that extends theme settings options' +version: VERSION +core: 8.x +base theme: test_basetheme diff --git a/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.theme b/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.theme new file mode 100644 index 0000000..04628c8 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_alter/test_theme_alter.theme @@ -0,0 +1,12 @@ + 'vertical_tabs', + ); + $form['extra'] = array( + '#type' => 'details', + '#title' => t('Extra'), + '#group' => 'extra_settings', + ); + $form['extra']['custom_flag'] = array( + '#type' => 'checkbox', + '#title' => t('Custom flag.'), + '#default_value' => theme_get_setting('custom_flag'), + ); + $form['extra']['custom_text'] = array( + '#type' => 'textfield', + '#title' => t('Custom textfield.'), + '#default_value' => theme_get_setting('custom_text'), + ); + $default_file_dir = 'public://template/logos'; + $logo_folder = file_prepare_directory($default_file_dir, FILE_CREATE_DIRECTORY); + $form['extra']['custom_logo'] = array( + '#type' => 'managed_file', + '#title' => t('Secondary logo.'), + '#default_value' => theme_get_setting('custom_logo'), + '#progress_indicator' => 'bar', + '#progress_message' => t('Please wait...'), + '#upload_location' => $logo_folder, + '#upload_validators' => array( + 'file_validate_extensions' => array('gif png jpg jpeg'), + 'file_validate_image_resolution' => array('30x50', '88x100'), + ), + ); + // Add a new submission handler. + $form['#submit'][] = 'test_theme_alter_form_system_theme_settings_submit'; +} + +/** + * Test theme form settings submission handler. + */ +function test_theme_alter_form_system_theme_settings_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { + if ($form_state->getValue('custom_logo')) { + $element = $form_state->getValue('custom_logo'); + if (!empty($element[0])){ + // Make submited files permanent. + $file = \Drupal\file\Entity\File::load($fid); + $file->setPermanent(); + $file->save(); + } + } +}