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 2ad98931a3e6377ca51c772b0f04c277feb15f4c..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',
+          ],
+        ],
       ];
     }
 
@@ -367,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.
@@ -492,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.