From a56ce007e215e6154c18166f7098e52ee81dd3b1 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 3 May 2023 12:53:22 +0100
Subject: [PATCH] Issue #2272011 by mashermike, quietone, mikeryan, rpayanm:
 SiteSettingsForm needs to include install.inc

---
 .../Core/Installer/Form/SiteSettingsForm.php  |  8 +++++
 .../install_form_test.info.yml                |  5 +++
 .../install_form_test.routing.yml             |  7 ++++
 .../src/Form/ExtendedForm.php                 | 11 +++++++
 .../Installer/SiteSettingsFormTest.php        | 33 +++++++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 core/modules/system/tests/modules/install_form_test/install_form_test.info.yml
 create mode 100644 core/modules/system/tests/modules/install_form_test/install_form_test.routing.yml
 create mode 100644 core/modules/system/tests/modules/install_form_test/src/Form/ExtendedForm.php
 create mode 100644 core/tests/Drupal/FunctionalTests/Installer/SiteSettingsFormTest.php

diff --git a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
index 0f1f25bb914d..739d6177414c 100644
--- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
+++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
@@ -67,6 +67,8 @@ public function getFormId() {
    * {@inheritdoc}
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
+    // Make sure the install API is available.
+    include_once DRUPAL_ROOT . '/core/includes/install.inc';
     $settings_file = './' . $this->sitePath . '/settings.php';
 
     $form['#title'] = $this->t('Database configuration');
@@ -155,6 +157,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    * {@inheritdoc}
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
+    // Make sure the install API is available.
+    include_once DRUPAL_ROOT . '/core/includes/install.inc';
+
     $driver = $form_state->getValue('driver');
     $database = $form_state->getValue($driver);
     $drivers = drupal_get_database_types();
@@ -236,6 +241,9 @@ public static function getDatabaseErrorsTemplate(array $errors) {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     global $install_state;
 
+    // Make sure the install API is available.
+    include_once DRUPAL_ROOT . '/core/includes/install.inc';
+
     // Update global settings array and save.
     $settings = [];
     $database = $form_state->get('database');
diff --git a/core/modules/system/tests/modules/install_form_test/install_form_test.info.yml b/core/modules/system/tests/modules/install_form_test/install_form_test.info.yml
new file mode 100644
index 000000000000..fb0457d495d4
--- /dev/null
+++ b/core/modules/system/tests/modules/install_form_test/install_form_test.info.yml
@@ -0,0 +1,5 @@
+name: Install Form Test
+type: module
+description: Test the SiteSettingsForm can be extended.
+package: Testing
+version: VERSION
diff --git a/core/modules/system/tests/modules/install_form_test/install_form_test.routing.yml b/core/modules/system/tests/modules/install_form_test/install_form_test.routing.yml
new file mode 100644
index 000000000000..9d5ec44479ee
--- /dev/null
+++ b/core/modules/system/tests/modules/install_form_test/install_form_test.routing.yml
@@ -0,0 +1,7 @@
+install_form_test.test-form:
+  path: /test-form
+  defaults:
+    _form: \Drupal\install_form_test\Form\ExtendedForm
+    _title: Extended Site Settings Form
+  requirements:
+    _access: 'TRUE'
diff --git a/core/modules/system/tests/modules/install_form_test/src/Form/ExtendedForm.php b/core/modules/system/tests/modules/install_form_test/src/Form/ExtendedForm.php
new file mode 100644
index 000000000000..613519ead3cd
--- /dev/null
+++ b/core/modules/system/tests/modules/install_form_test/src/Form/ExtendedForm.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Drupal\install_form_test\Form;
+
+use Drupal\Core\Installer\Form\SiteSettingsForm;
+
+/**
+ * Extends the site setting form.
+ */
+class ExtendedForm extends SiteSettingsForm {
+}
diff --git a/core/tests/Drupal/FunctionalTests/Installer/SiteSettingsFormTest.php b/core/tests/Drupal/FunctionalTests/Installer/SiteSettingsFormTest.php
new file mode 100644
index 000000000000..58fd60ab8194
--- /dev/null
+++ b/core/tests/Drupal/FunctionalTests/Installer/SiteSettingsFormTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Drupal\FunctionalTests\Installer;
+
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests the extension of the site settings form.
+ *
+ * @group Installer
+ */
+class SiteSettingsFormTest extends BrowserTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['install_form_test'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $defaultTheme = 'stark';
+
+  /**
+   * Confirms that the form is extensible.
+   */
+  public function testSiteSettingsForm() {
+    // Test that the form page can be loaded without errors.
+    $this->drupalGet('test-form');
+    $this->assertSession()->statusCodeEquals(200);
+  }
+
+}
-- 
GitLab