protected function ChannelForm::buildLanguageSelect in Entity Share 8
Same name and namespace in other branches
- 8.3 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::buildLanguageSelect()
- 8.2 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::buildLanguageSelect()
Helper function to generate language select.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
1 call to ChannelForm::buildLanguageSelect()
- 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 262
Class
- ChannelForm
- Class ChannelForm.
Namespace
Drupal\entity_share_server\FormCode
protected function buildLanguageSelect(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
$channel = $this->entity;
$channel_entity_type = $channel
->get('channel_entity_type');
$channel_bundle = $channel
->get('channel_bundle');
$selected_entity_type = $form_state
->getValue('channel_entity_type');
$selected_bundle = $form_state
->getValue('channel_bundle');
// No bundle selected and the channel does not have any.
if (empty($selected_bundle) && $channel_bundle == '') {
return;
}
if (!empty($selected_entity_type) && !empty($selected_bundle)) {
$entity_type = $selected_entity_type;
$bundle = $selected_bundle;
}
else {
$entity_type = $channel_entity_type;
$bundle = $channel_bundle;
}
// Check if the bundle is translatable.
if (isset($this->bundleInfos[$entity_type][$bundle]['translatable']) && $this->bundleInfos[$entity_type][$bundle]['translatable']) {
$form['bundle_wrapper']['language_wrapper']['channel_langcode'] = [
'#type' => 'language_select',
'#title' => $this
->t('Language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $channel
->get('channel_langcode'),
];
}
else {
$form['bundle_wrapper']['language_wrapper']['channel_langcode'] = [
'#type' => 'value',
'#value' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
];
}
}