You are here

public function CustomServicesEditForm::buildForm in Shorten URLs 8.2

Same name and namespace in other branches
  1. 8 modules/shorten_cs/src/Form/CustomServicesEditForm.php \Drupal\shorten_cs\Form\CustomServicesEditForm::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 ConfigFormBase::buildForm

File

modules/shorten_cs/src/Form/CustomServicesEditForm.php, line 94

Class

CustomServicesEditForm
Settings form.

Namespace

Drupal\shorten_cs\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $service = NULL) {
  $form = $this->formBuilder
    ->getForm('Drupal\\shorten_cs\\Form\\CustomServicesAddForm');
  $sid = $service;
  $service = $this->database
    ->select('shorten_cs', 's')
    ->fields('s')
    ->condition('sid', intval($sid))
    ->execute()
    ->fetchAssoc();
  foreach ([
    'name',
    'url',
    'type',
    'tag',
  ] as $key) {
    $form[$key]['#default_value'] = $service[$key];
    unset($form[$key]['#value']);
  }
  $form['sid'] = [
    '#type' => 'value',
    '#value' => $service['sid'],
  ];
  $form['old_name'] = [
    '#type' => 'value',
    '#value' => $service['name'],
  ];
  return parent::buildForm($form, $form_state);
}