public function ShurlyCreateForm::buildForm in ShURLy 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 FormInterface::buildForm
File
- src/
Form/ ShurlyCreateForm.php, line 23
Class
- ShurlyCreateForm
- ShurlyCreateForm.
Namespace
Drupal\shurly\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['wrapper'] = [
'#prefix' => '<div id="shurly-create">',
'#suffix' => '</div>',
];
$form['wrapper']['long_url'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $form_state
->getValue('long_url'),
'#maxlength' => 2048,
'#placeholder' => $this
->t('Shorten your link'),
'#attributes' => [
'autocomplete' => 'off',
],
];
$form['wrapper']['options'] = [
'#type' => 'details',
'#title' => $this
->t('Custom URL'),
'#access' => \Drupal::currentUser()
->hasPermission('Enter custom URLs'),
];
$form['wrapper']['options']['short_url'] = [
'#type' => 'textfield',
'#default_value' => $form_state
->getValue('short_url'),
'#size' => 6,
'#field_prefix' => _shurly_get_shurly_base() . '/',
'#attributes' => [
'autocomplete' => 'off',
],
];
$form['wrapper']['actions'] = [
'#type' => 'actions',
];
$form['wrapper']['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Shorten'),
'#attributes' => [
'tabindex' => 3,
],
'#ajax' => [
'callback' => '::submitAjaxCall',
'wrapper' => 'shurly-create',
'event' => 'click',
],
];
$form['wrapper']['actions']['reset'] = [
'#type' => 'submit',
'#value' => t('Shorten another'),
'#attributes' => [
'tabindex' => 3,
],
'#access' => FALSE,
'#ajax' => [
'callback' => '::resetAjaxCall',
'wrapper' => 'shurly-create',
'event' => 'click',
],
];
return $form;
}