diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8bc406101b1adabecc75b4ebcd3e2512414a0b21..4563f666ea7d933d3e4e6affb45eaabb21692054 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,6 +12,7 @@ Drupal 7.xx, xxxx-xx-xx (development version) - PHP 7.2: Removed deprecated function each(). - PHP 7.2: Avoid count() calls on uncountable variables. - PHP 7.2: Removed deprecated create_function() call. +- Fixed theme-settings.php not being loaded on cached forms Drupal 7.59, 2018-04-25 ----------------------- diff --git a/modules/simpletest/tests/themes/test_theme/theme-settings.php b/modules/simpletest/tests/themes/test_theme/theme-settings.php new file mode 100644 index 0000000000000000000000000000000000000000..cb51d942e78cfd7dee5f999a5d420b1cde98f4eb --- /dev/null +++ b/modules/simpletest/tests/themes/test_theme/theme-settings.php @@ -0,0 +1,32 @@ + 'checkbox', + '#title' => 'Test theme checkbox', + '#default_value' => theme_get_setting('test_theme_checkbox'), + ); + + // Force the form to be cached so we can test that this file is properly + // loaded and the custom submit handler is properly called even on a cached + // form build. + $form_state['cache'] = TRUE; + $form['#submit'][] = 'test_theme_form_system_theme_settings_submit'; +} + +/** + * Form submission handler for the test theme settings form. + * + * @see test_theme_form_system_theme_settings_alter() + */ +function test_theme_form_system_theme_settings_submit($form, &$form_state) { + drupal_set_message('The test theme setting was saved.'); +} diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 51c238bf78180a1fd7a1be6fa19934d866a488a3..b7e6fc9e706b242579da836dc27fe1a5e5e9be30 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -572,9 +572,10 @@ function system_theme_settings($form, &$form_state, $key = '') { // Process the theme and all its base themes. foreach ($theme_keys as $theme) { // Include the theme-settings.php file. - $filename = DRUPAL_ROOT . '/' . str_replace("/$theme.info", '', $themes[$theme]->filename) . '/theme-settings.php'; - if (file_exists($filename)) { - require_once $filename; + $theme_settings_path = drupal_get_path('theme', $theme) . '/theme-settings.php'; + if (file_exists(DRUPAL_ROOT . '/' . $theme_settings_path)) { + require_once DRUPAL_ROOT . '/' . $theme_settings_path; + $form_state['build_info']['files'][] = $theme_settings_path; } // Call theme-specific settings. diff --git a/modules/system/system.test b/modules/system/system.test index 9eaf562b28c15bcfc4021d5b8be6cfd1e8743f5d..5ae3341612f464b8ffff938eaf659ff14d42fb9c 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -1944,6 +1944,30 @@ class SystemThemeFunctionalTest extends DrupalWebTestCase { $this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename)); } + + /** + * Test the individual per-theme settings form. + */ + function testPerThemeSettings() { + // Enable the test theme and the module that controls it. Clear caches in + // between so that the module's hook_system_theme_info() implementation is + // correctly registered. + module_enable(array('theme_test')); + drupal_flush_all_caches(); + theme_enable(array('test_theme')); + + // Test that the theme-specific settings form can be saved and that the + // theme-specific checkbox is checked and unchecked as appropriate. + $this->drupalGet('admin/appearance/settings/test_theme'); + $this->assertNoFieldChecked('edit-test-theme-checkbox', 'The test_theme_checkbox setting is unchecked.'); + $this->drupalPost(NULL, array('test_theme_checkbox' => TRUE), t('Save configuration')); + $this->assertText('The test theme setting was saved.'); + $this->assertFieldChecked('edit-test-theme-checkbox', 'The test_theme_checkbox setting is checked.'); + $this->drupalPost(NULL, array('test_theme_checkbox' => FALSE), t('Save configuration')); + $this->assertText('The test theme setting was saved.'); + $this->assertNoFieldChecked('edit-test-theme-checkbox', 'The test_theme_checkbox setting is unchecked.'); + } + /** * Test the administration theme functionality. */