You are here

public function CustomServicesAddForm::buildForm in Shorten URLs 8

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

Class

CustomServicesAddForm
Settings form.

Namespace

Drupal\shorten_cs\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  $config = $this
    ->config('shorten.settings');
  $table = $this
    ->shorten_cs_services_table();
  if (!empty($table)) {
    $form['custom_services'] = [
      '#markup' => $table,
    ];
  }
  $form['#attached']['library'][] = 'shorten_cs/shorten_cs';
  if (!isset($form) || !is_array($form)) {
    $form = array();
  }
  $form['#attributes'] = array(
    'class' => 'shorten-cs-apply-js',
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('The name of the service'),
    '#required' => TRUE,
  );
  $form['url'] = array(
    '#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'] = array(
    '#type' => 'radios',
    '#title' => t('Response type'),
    '#description' => t('The type of response the API endpoint returns.'),
    '#required' => TRUE,
    '#default_value' => 'text',
    '#options' => array(
      'text' => t('Text'),
      'xml' => 'XML',
      'json' => 'JSON',
    ),
  );
  $form['tag'] = array(
    '#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.'),
  );
  return parent::buildForm($form, $form_state);
}