function Tasks::getFormOptions

Same name in this branch
  1. 10 core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks::getFormOptions()
  2. 10 core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks::getFormOptions()
  3. 10 core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks::getFormOptions()
Same name in other branches
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks::getFormOptions()
  2. 9 core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks::getFormOptions()
  3. 9 core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks::getFormOptions()
  4. 9 core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks::getFormOptions()
  5. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php \Drupal\Core\Database\Driver\sqlite\Install\Tasks::getFormOptions()
  6. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php \Drupal\Core\Database\Driver\mysql\Install\Tasks::getFormOptions()
  7. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php \Drupal\Core\Database\Driver\pgsql\Install\Tasks::getFormOptions()
  8. 8.9.x core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks::getFormOptions()
  9. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php \Drupal\sqlite\Driver\Database\sqlite\Install\Tasks::getFormOptions()
  10. 11.x core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php \Drupal\mysql\Driver\Database\mysql\Install\Tasks::getFormOptions()
  11. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php \Drupal\pgsql\Driver\Database\pgsql\Install\Tasks::getFormOptions()
  12. 11.x core/lib/Drupal/Core/Database/Install/Tasks.php \Drupal\Core\Database\Install\Tasks::getFormOptions()

Returns driver specific configuration options.

Parameters

string[] $database: An array of driver specific configuration options.

Return value

array The options form array.

3 calls to Tasks::getFormOptions()
Tasks::getFormOptions in core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php
Returns driver specific configuration options.
Tasks::getFormOptions in core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php
Returns driver specific configuration options.
Tasks::getFormOptions in core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
Returns driver specific configuration options.
3 methods override Tasks::getFormOptions()
Tasks::getFormOptions in core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php
Returns driver specific configuration options.
Tasks::getFormOptions in core/modules/mysql/src/Driver/Database/mysql/Install/Tasks.php
Returns driver specific configuration options.
Tasks::getFormOptions in core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
Returns driver specific configuration options.

File

core/lib/Drupal/Core/Database/Install/Tasks.php, line 251

Class

Tasks
Database installer structure.

Namespace

Drupal\Core\Database\Install

Code

public function getFormOptions(array $database) {
    // Use reflection to determine the driver name.
    // @todo https:///www.drupal.org/node/3123240 Provide a better way to get
    //   the driver name.
    $reflection = new \ReflectionClass($this);
    $dir_parts = explode(DIRECTORY_SEPARATOR, dirname($reflection->getFileName(), 2));
    $driver = array_pop($dir_parts);
    $form['database'] = [
        '#type' => 'textfield',
        '#title' => t('Database name'),
        '#default_value' => empty($database['database']) ? '' : $database['database'],
        '#size' => 45,
        '#required' => TRUE,
        '#states' => [
            'required' => [
                ':input[name=driver]' => [
                    'value' => $driver,
                ],
            ],
        ],
    ];
    $form['username'] = [
        '#type' => 'textfield',
        '#title' => t('Database username'),
        '#default_value' => empty($database['username']) ? '' : $database['username'],
        '#size' => 45,
        '#required' => TRUE,
        '#states' => [
            'required' => [
                ':input[name=driver]' => [
                    'value' => $driver,
                ],
            ],
        ],
    ];
    $form['password'] = [
        '#type' => 'password',
        '#title' => t('Database password'),
        '#default_value' => empty($database['password']) ? '' : $database['password'],
        '#required' => FALSE,
        '#size' => 45,
    ];
    $form['advanced_options'] = [
        '#type' => 'details',
        '#title' => t('Advanced options'),
        '#weight' => 10,
    ];
    global $install_state;
    $profile = $install_state['parameters']['profile'] ?? NULL;
    $db_prefix = $profile == 'standard' ? 'drupal_' : $profile . '_';
    $form['advanced_options']['prefix'] = [
        '#type' => 'textfield',
        '#title' => t('Table name prefix'),
        '#default_value' => empty($database['prefix']) ? '' : $database['prefix'],
        '#size' => 45,
        '#description' => t('If more than one application will be sharing this database, a unique table name prefix – such as %prefix – will prevent collisions.', [
            '%prefix' => $db_prefix,
        ]),
        '#weight' => 10,
    ];
    $form['advanced_options']['host'] = [
        '#type' => 'textfield',
        '#title' => t('Host'),
        '#default_value' => empty($database['host']) ? 'localhost' : $database['host'],
        '#size' => 45,
        // Host names can be 255 characters long.
'#maxlength' => 255,
        '#required' => TRUE,
    ];
    $form['advanced_options']['port'] = [
        '#type' => 'number',
        '#title' => t('Port number'),
        '#default_value' => empty($database['port']) ? '' : $database['port'],
        '#min' => 0,
        '#max' => 65535,
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.