summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Franz2018-06-26 11:26:50 (GMT)
committerFabian Franz2018-06-26 11:26:50 (GMT)
commitb014c196e1eab417e0703c3fc77e340a213a8824 (patch)
treed79ac9c9c364c2ac65b61461717e5b0ba8c8f20a
parent76a4dc7098771a14e7d64a827457dcadd7feafbc (diff)
Issue #2900373 by David_Rothstein, joseph.olstad, jollysolutions, joelpittet: [D7] When a theme has a managed_file field and a submit callback, call to undefined function error is thrown7.x
-rw-r--r--CHANGELOG.txt1
-rw-r--r--modules/simpletest/tests/themes/test_theme/theme-settings.php32
-rw-r--r--modules/system/system.admin.inc7
-rw-r--r--modules/system/system.test24
4 files changed, 61 insertions, 3 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 8bc4061..4563f66 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 0000000..cb51d94
--- /dev/null
+++ b/modules/simpletest/tests/themes/test_theme/theme-settings.php
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * @file
+ * Theme setting callbacks for the test_theme theme.
+ */
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function test_theme_form_system_theme_settings_alter(&$form, &$form_state) {
+ $form['test_theme_checkbox'] = array(
+ '#type' => '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 51c238b..b7e6fc9 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 9eaf562..5ae3341 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.
*/