You are here

public function EditViewsCustomTable::buildForm in Views Custom Table 8

Same name and namespace in other branches
  1. 9.0.x src/Form/EditViewsCustomTable.php \Drupal\view_custom_table\Form\EditViewsCustomTable::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/EditViewsCustomTable.php, line 61

Class

EditViewsCustomTable
Edit views custom table form.

Namespace

Drupal\view_custom_table\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $table_name = NULL) {
  $config = $this->config
    ->getRawData();
  $all_database_connections = Database::getAllConnectionInfo();
  foreach ($all_database_connections as $connection_name => $connection) {
    $displyName = $connection['default']['database'];
    $databaseOptions[$connection_name] = $displyName;
  }
  $form['table_database'] = [
    '#type' => 'select',
    '#options' => $databaseOptions,
    '#title' => $this
      ->t('Database'),
    '#default_value' => $config[$table_name]['table_database'],
    '#disabled' => TRUE,
    '#description' => $this
      ->t('Database of the table cannot be changed.'),
  ];
  $form['table_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Table'),
    '#default_value' => $table_name,
    '#disabled' => TRUE,
    '#required' => TRUE,
    '#description' => $this
      ->t('Table name cannot be changed.'),
  ];
  $form['description'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $config[$table_name]['description'] != NULL ? $config[$table_name]['description'] : '',
    '#rows' => 5,
    '#description' => $this
      ->t('Maximum 255 letters are allowed.'),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => $this
      ->buildCancelLinkUrl(),
  ];
  return $form;
}