You are here

protected function ChannelForm::buildBundleSelect in Entity Share 8

Same name and namespace in other branches
  1. 8.3 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::buildBundleSelect()
  2. 8.2 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::buildBundleSelect()

Helper function to generate bundle select.

Parameters

array $form: The form array.

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

1 call to ChannelForm::buildBundleSelect()
ChannelForm::form in modules/entity_share_server/src/Form/ChannelForm.php
Gets the actual form array to be built.

File

modules/entity_share_server/src/Form/ChannelForm.php, line 212

Class

ChannelForm
Class ChannelForm.

Namespace

Drupal\entity_share_server\Form

Code

protected function buildBundleSelect(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
  $channel = $this->entity;
  $channel_entity_type = $channel
    ->get('channel_entity_type');
  $selected_entity_type = $form_state
    ->getValue('channel_entity_type');

  // No entity type selected and the channel does not have any.
  if (empty($selected_entity_type) && $channel_entity_type == '') {
    return;
  }
  if (!empty($selected_entity_type)) {
    $entity_type = $selected_entity_type;
  }
  else {
    $entity_type = $channel_entity_type;
  }
  $form['bundle_wrapper']['channel_bundle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Bundle'),
    '#options' => $this
      ->getBundleOptions($entity_type),
    '#empty_value' => '',
    '#default_value' => $channel
      ->get('channel_bundle'),
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxLanguageSelect',
      ],
      'wrapper' => 'language-wrapper',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ];

  // Container for the AJAX.
  $form['bundle_wrapper']['language_wrapper'] = [
    '#type' => 'container',
    // Force an id because otherwise default id is changed when using AJAX.
    '#attributes' => [
      'id' => 'language-wrapper',
    ],
  ];
}