You are here

public function ChannelForm::form in Entity Share 8.3

Same name and namespace in other branches
  1. 8 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::form()
  2. 8.2 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::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_server/src/Form/ChannelForm.php, line 67

Class

ChannelForm
Entity form for the channel entity.

Namespace

Drupal\entity_share_server\Form

Code

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

  /** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
  $channel = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $channel
      ->label(),
    '#description' => $this
      ->t('Label for the channel.'),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $channel
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\entity_share_server\\Entity\\Channel::load',
    ],
    '#disabled' => !$channel
      ->isNew(),
  ];
  $form['channel_entity_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Entity type'),
    '#options' => $this
      ->getEntityTypeOptions(),
    '#empty_value' => '',
    '#default_value' => $channel
      ->get('channel_entity_type'),
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxBundleSelect',
      ],
      'effect' => 'fade',
      'method' => 'replace',
      'wrapper' => 'bundle-wrapper',
    ],
  ];

  // Container for the AJAX.
  $form['bundle_wrapper'] = [
    '#type' => 'container',
    // Force an id because otherwise default id is changed when using AJAX.
    '#attributes' => [
      'id' => 'bundle-wrapper',
    ],
  ];
  $this
    ->buildBundleSelect($form, $form_state);
  $this
    ->buildLanguageSelect($form, $form_state);
  $this
    ->buildGroupsTable($form, $form_state);
  $this
    ->buildFiltersTable($form, $form_state);
  $this
    ->buildSearchesTable($form, $form_state);
  $this
    ->buildSortsTable($form, $form_state);
  $authorized_users = $channel
    ->get('authorized_users');
  $form['authorized_users'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Authorized users'),
    '#description' => $this
      ->t('Only users with the %entity_share_server_access_channels permission are listed.', [
      '%entity_share_server_access_channels' => $this
        ->t('Access channels list'),
    ]),
    '#options' => $this
      ->getAuthorizedUsersOptions(),
    '#default_value' => !is_null($authorized_users) ? $authorized_users : [],
  ];
  return $form;
}