Setup UI - Display "Administrator" options (on standalone)
authorTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 05:55:00 +0000 (22:55 -0700)
committerTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 06:10:07 +0000 (23:10 -0700)
setup/plugins/blocks/admin.civi-setup.php [new file with mode: 0644]
setup/plugins/blocks/admin.tpl.php [new file with mode: 0644]

diff --git a/setup/plugins/blocks/admin.civi-setup.php b/setup/plugins/blocks/admin.civi-setup.php
new file mode 100644 (file)
index 0000000..6eb72e0
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+if (!defined('CIVI_SETUP')) {
+  exit("Installation plugins must only be loaded by the installer.\n");
+}
+
+\Civi\Setup::dispatcher()
+  ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent $e) {
+    \Civi\Setup::log()->info(sprintf('[%s] Register blocks', basename(__FILE__)));
+
+    /**
+     * @var \Civi\Setup\UI\SetupController $ctrl
+     */
+    $ctrl = $e->getCtrl();
+
+    $ctrl->blocks['admin'] = [
+      'is_active' => ($e->getModel()->cms === 'Standalone'),
+      'file' => __DIR__ . DIRECTORY_SEPARATOR . 'admin.tpl.php',
+      'class' => 'if-no-errors',
+      'weight' => 35,
+    ];
+
+    if ($ctrl->blocks['admin']['is_active'] && $e->getMethod() === 'POST') {
+      if ($e->getField('adminUser')) {
+        $e->getModel()->extras['adminUser'] = $e->getField('adminUser');
+      }
+      if ($e->getField('adminPass')) {
+        $e->getModel()->extras['adminPassWasSpecified'] = TRUE;
+        $e->getModel()->extras['adminPass'] = $e->getField('adminPass');
+      }
+    }
+
+  }, \Civi\Setup::PRIORITY_PREPARE);
diff --git a/setup/plugins/blocks/admin.tpl.php b/setup/plugins/blocks/admin.tpl.php
new file mode 100644 (file)
index 0000000..5b3f33f
--- /dev/null
@@ -0,0 +1,14 @@
+<?php if (!defined('CIVI_SETUP')): exit("Installation plugins must only be loaded by the installer.\n");
+endif; ?>
+
+<h2><?php echo ts('Administrator'); ?></h2>
+
+<p style="margin-left: 2em">
+  <label for="adminUser"><span><?php echo ts('Administrative User:'); ?></span></label>
+  <input type="text" id="adminUser" name="civisetup[adminUser]" value="<?php echo htmlentities($model->extras['adminUser'] ?? '') ?>">
+</p>
+
+<p style="margin-left: 2em">
+  <label for="adminPass"><span><?php echo ts('Administrative Password:'); ?></span></label>
+  <input type="password" id="adminPass" name="civisetup[adminPass]" value="<?php echo htmlentities($model->extras['adminPass'] ?? '') ?>">
+</p>