public function CallbackForm::buildForm in Empty Page 8
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
- src/
Form/ CallbackForm.php, line 30
Class
- CallbackForm
- Builds the form for callbacks add/edit form.
Namespace
Drupal\empty_page\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $cid = NULL) {
// If $cid exists, we're editing.
$callback = NULL;
$settings = $this->configFactory
->get('empty_page.settings');
if (!empty($cid)) {
$callback = $settings
->get('callback_' . $cid);
}
if ($callback) {
$this->cid = $cid;
$form_title = $this
->t('Edit callback');
}
else {
$form_title = $this
->t('Create a new callback');
}
$form['empty_page_basic'] = [
'#type' => 'details',
'#title' => $form_title,
'#description' => '',
'#open' => TRUE,
];
$form['empty_page_basic']['empty_page_callback_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Internal path'),
'#description' => '',
'#required' => 1,
'#default_value' => $callback ? $callback['path'] : '',
];
$form['empty_page_basic']['empty_page_callback_page_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Page title'),
'#description' => '',
'#default_value' => $callback ? $callback['page_title'] : '',
];
$form['empty_page_basic']['buttons']['submit'] = [
'#type' => 'submit',
'#value' => $callback ? $this
->t('Save') : $this
->t('Add'),
];
return $form;
}