public function CustomServicesAddForm::buildForm in Shorten URLs 8.2
Same name and namespace in other branches
- 8 modules/shorten_cs/src/Form/CustomServicesAddForm.php \Drupal\shorten_cs\Form\CustomServicesAddForm::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/ CustomServicesAddForm.php, line 97
Class
- CustomServicesAddForm
- Settings form.
Namespace
Drupal\shorten_cs\FormCode
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('shorten.settings');
$table = $this
->shortenCsServicesTable();
if (!empty($table)) {
$form['custom_services'] = [
'#markup' => $table,
];
}
$form['#attached']['library'][] = 'shorten_cs/shorten_cs';
if (!isset($form) || !is_array($form)) {
$form = [];
}
$form['#attributes'] = [
'class' => 'shorten-cs-apply-js',
];
$form['name'] = [
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The name of the service'),
'#required' => TRUE,
];
$form['url'] = [
'#type' => 'textfield',
'#title' => t('API endpoint URL'),
'#description' => t('The URL of the API endpoint, with parameters,
such that the long URL can be appended to the end.') . ' ' . t('For example, the endpoint for TinyURL is') . ' <code>http://tinyurl.com/api-create.php?url=</code>. ' . t('Appending a long URL to the endpoint
and then visiting that address will return data about the shortened URL.'),
'#required' => TRUE,
];
$form['type'] = [
'#type' => 'radios',
'#title' => t('Response type'),
'#description' => t('The type of response the API endpoint returns.'),
'#required' => TRUE,
'#default_value' => 'text',
'#options' => [
'text' => t('Text'),
'xml' => 'XML',
'json' => 'JSON',
],
];
$form['tag'] = [
'#type' => 'textfield',
'#title' => t('XML tag or JSON key'),
'#description' => t('The XML tag or JSON key that identifies the full short URL in the API response.') . ' ' . t('Only required for XML and JSON response types.') . '<br> ' . t('For multidimensional JSON responses, a path can be specified using ' . 'dot notation in order to specify the element in containing the ' . 'short url. For example, the path \'data.url\' would point to the ' . 'url value in the following JSON response: <br>' . '{"data":{"url":"http://ex.am/ple"}}<br>' . 'If a JSON element name itself contains a dot character, it can be ' . 'wrapped in double quotes.'),
];
return parent::buildForm($form, $form_state);
}