You are here

public function RemoteForm::form in Entity Share 8

Same name and namespace in other branches
  1. 8.3 modules/entity_share_client/src/Form/RemoteForm.php \Drupal\entity_share_client\Form\RemoteForm::form()
  2. 8.2 modules/entity_share_client/src/Form/RemoteForm.php \Drupal\entity_share_client\Form\RemoteForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/entity_share_client/src/Form/RemoteForm.php, line 19

Class

RemoteForm
Class RemoteForm.

Namespace

Drupal\entity_share_client\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var \Drupal\entity_share_client\Entity\RemoteInterface $remote */
  $remote = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $remote
      ->label(),
    '#description' => $this
      ->t('Label for the remote website.'),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $remote
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\entity_share_client\\Entity\\Remote::load',
    ],
    '#disabled' => !$remote
      ->isNew(),
  ];
  $form['url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('URL'),
    '#maxlength' => 255,
    '#description' => $this
      ->t('The remote URL. Example: http://example.com'),
    '#default_value' => $remote
      ->get('url'),
    '#required' => TRUE,
  ];
  $form['basic_auth'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Basic Auth'),
  ];
  $form['basic_auth']['basic_auth_username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Username'),
    '#default_value' => $remote
      ->get('basic_auth_username'),
    '#required' => TRUE,
  ];
  $form['basic_auth']['basic_auth_password'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Password'),
    '#required' => TRUE,
  ];
  return $form;
}