You are here

public function PullForm::buildForm in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::buildForm()
  2. 8 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::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 FormInterface::buildForm

File

modules/entity_share_client/src/Form/PullForm.php, line 196

Class

PullForm
Form controller to pull entities.

Namespace

Drupal\entity_share_client\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $remote_options = $this
    ->prepareRemoteOptions();
  $remote_disabled = FALSE;
  $remote_default_value = $this->query
    ->get('remote');

  // If only one option. Pre-select it and disable the select.
  if (count($remote_options) == 1) {
    $remote_disabled = TRUE;
    $remote_default_value = key($remote_options);
    $form_state
      ->setValue('remote', $remote_default_value);
  }
  $form['remote'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Remote website'),
    '#options' => $remote_options,
    '#default_value' => $remote_default_value,
    '#empty_value' => '',
    '#required' => TRUE,
    '#disabled' => $remote_disabled,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxChannelSelect',
      ],
      'effect' => 'fade',
      'method' => 'replace',
      'wrapper' => 'channel-wrapper',
    ],
  ];

  // Container for the AJAX.
  $form['channel_wrapper'] = [
    '#type' => 'container',
    // Force an id because otherwise default id is changed when using AJAX.
    '#attributes' => [
      'id' => 'channel-wrapper',
    ],
  ];
  $this
    ->buildChannelSelect($form, $form_state);
  return $form;
}