You are here

public function CustomServicesEditForm::buildForm in Shorten URLs 8

Same name and namespace in other branches
  1. 8.2 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 33

Class

CustomServicesEditForm
Settings form.

Namespace

Drupal\shorten_cs\Form

Code

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