Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / src / Form / ThemeSettingsForm.php
index f5cfb090826095502702deace675154248c0642b..907e5ce3d2de1434d102de360a3b94c34a5433dd 100644 (file)
@@ -16,6 +16,8 @@ use Drupal\Core\Theme\ThemeManagerInterface;
 
 /**
  * Displays theme configuration for entire site and individual themes.
+ *
+ * @internal
  */
 class ThemeSettingsForm extends ConfigFormBase {
 
@@ -134,11 +136,11 @@ class ThemeSettingsForm extends ConfigFormBase {
 
     $form['var'] = [
       '#type' => 'hidden',
-      '#value' => $var
+      '#value' => $var,
     ];
     $form['config_key'] = [
       '#type' => 'hidden',
-      '#value' => $config_key
+      '#value' => $config_key,
     ];
 
     // Toggle settings
@@ -212,7 +214,10 @@ class ThemeSettingsForm extends ConfigFormBase {
         '#type' => 'file',
         '#title' => t('Upload logo image'),
         '#maxlength' => 40,
-        '#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
+        '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
+        '#upload_validators' => [
+          'file_validate_is_image' => [],
+        ],
       ];
     }
 
@@ -252,7 +257,12 @@ class ThemeSettingsForm extends ConfigFormBase {
       $form['favicon']['settings']['favicon_upload'] = [
         '#type' => 'file',
         '#title' => t('Upload favicon image'),
-        '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
+        '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon."),
+        '#upload_validators' => [
+          'file_validate_extensions' => [
+            'ico png gif jpg jpeg apng svg',
+          ],
+        ],
       ];
     }
 
@@ -324,9 +334,21 @@ class ThemeSettingsForm extends ConfigFormBase {
       // Process the theme and all its base themes.
       foreach ($theme_keys as $theme) {
         // Include the theme-settings.php file.
-        $filename = DRUPAL_ROOT . '/' . $themes[$theme]->getPath() . '/theme-settings.php';
-        if (file_exists($filename)) {
-          require_once $filename;
+        $theme_path = drupal_get_path('theme', $theme);
+        $theme_settings_file = $theme_path . '/theme-settings.php';
+        $theme_file = $theme_path . '/' . $theme . '.theme';
+        $filenames = [$theme_settings_file, $theme_file];
+        foreach ($filenames as $filename) {
+          if (file_exists($filename)) {
+            require_once $filename;
+
+            // The file must be required for the cached form too.
+            $files = $form_state->getBuildInfo()['files'];
+            if (!in_array($filename, $files)) {
+              $files[] = $filename;
+            }
+            $form_state->addBuildInfo('files', $files);
+          }
         }
 
         // Call theme-specific settings.
@@ -355,37 +377,23 @@ class ThemeSettingsForm extends ConfigFormBase {
     parent::validateForm($form, $form_state);
 
     if ($this->moduleHandler->moduleExists('file')) {
-      // Handle file uploads.
-      $validators = ['file_validate_is_image' => []];
 
       // Check for a new uploaded logo.
-      $file = file_save_upload('logo_upload', $validators, FALSE, 0);
-      if (isset($file)) {
-        // File upload was attempted.
+      if (isset($form['logo'])) {
+        $file = _file_save_upload_from_form($form['logo']['settings']['logo_upload'], $form_state, 0);
         if ($file) {
           // Put the temporary file in form_values so we can save it on submit.
           $form_state->setValue('logo_upload', $file);
         }
-        else {
-          // File upload failed.
-          $form_state->setErrorByName('logo_upload', $this->t('The logo could not be uploaded.'));
-        }
       }
 
-      $validators = ['file_validate_extensions' => ['ico png gif jpg jpeg apng svg']];
-
       // Check for a new uploaded favicon.
-      $file = file_save_upload('favicon_upload', $validators, FALSE, 0);
-      if (isset($file)) {
-        // File upload was attempted.
+      if (isset($form['favicon'])) {
+        $file = _file_save_upload_from_form($form['favicon']['settings']['favicon_upload'], $form_state, 0);
         if ($file) {
           // Put the temporary file in form_values so we can save it on submit.
           $form_state->setValue('favicon_upload', $file);
         }
-        else {
-          // File upload failed.
-          $form_state->setErrorByName('favicon_upload', $this->t('The favicon could not be uploaded.'));
-        }
       }
 
       // When intending to use the default logo, unset the logo_path.
@@ -480,7 +488,7 @@ class ThemeSettingsForm extends ConfigFormBase {
    */
   protected function validatePath($path) {
     // Absolute local file paths are invalid.
-    if (drupal_realpath($path) == $path) {
+    if (\Drupal::service('file_system')->realpath($path) == $path) {
       return FALSE;
     }
     // A path relative to the Drupal root or a fully qualified URI is valid.