You are here

protected function PullForm::buildChannelSelect 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::buildChannelSelect()
  2. 8 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::buildChannelSelect()

Helper function to generate channel select.

Parameters

array $form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

1 call to PullForm::buildChannelSelect()
PullForm::buildForm in modules/entity_share_client/src/Form/PullForm.php
Form constructor.

File

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

Class

PullForm
Form controller to pull entities.

Namespace

Drupal\entity_share_client\Form

Code

protected function buildChannelSelect(array &$form, FormStateInterface $form_state) {
  $selected_remote = $form_state
    ->getValue('remote', $this->query
    ->get('remote'));

  // No remote selected.
  if (empty($this->remoteWebsites[$selected_remote])) {
    return;
  }
  $selected_remote = $this->remoteWebsites[$selected_remote];
  $this->channelsInfos = $this->remoteManager
    ->getChannelsInfos($selected_remote);
  $channel_options = $this
    ->getChannelOptions();
  $channel_disabled = FALSE;
  $channel_default_value = $this->query
    ->get('channel');

  // If only one channel. Pre-select it and disable the select.
  if (count($channel_options) == 1) {
    $channel_disabled = TRUE;
    $channel_default_value = key($channel_options);
    $form_state
      ->setValue('channel', $channel_default_value);
  }
  $form['channel_wrapper']['channel'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Channel'),
    '#options' => $channel_options,
    '#default_value' => $channel_default_value,
    '#empty_value' => '',
    '#required' => TRUE,
    '#disabled' => $channel_disabled,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxEntitiesSelectTable',
      ],
      'effect' => 'fade',
      'method' => 'replace',
      'wrapper' => 'entities-wrapper',
    ],
  ];

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