public function SocialGroupAddForm::getGroupTypeElement in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.2 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.3 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.4 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.5 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.6 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.7 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 8.8 modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 10.0.x modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 10.1.x modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
- 10.2.x modules/social_features/social_group/src/Form/SocialGroupAddForm.php \Drupal\social_group\Form\SocialGroupAddForm::getGroupTypeElement()
Get the group type element.
Note this element is also used in the edit group form.
Parameters
bool $container: Make this a containered radio element.
Return value
array Returns an array containing the group type element and descriptions.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to SocialGroupAddForm::getGroupTypeElement()
- SocialGroupAddForm::buildForm in modules/
social_features/ social_group/ src/ Form/ SocialGroupAddForm.php - Defines the settings form for Post entities.
File
- modules/
social_features/ social_group/ src/ Form/ SocialGroupAddForm.php, line 124
Class
- SocialGroupAddForm
- Class SocialGroupAddForm.
Namespace
Drupal\social_group\FormCode
public function getGroupTypeElement($container = FALSE) {
$user = \Drupal::currentUser();
$element = [
'#type' => 'radios',
'#title' => $this
->t('Group type'),
'#default_value' => 'open_group',
'#required' => TRUE,
'#cache' => [
'tags' => $this->entityTypeManager
->getDefinition('group_type')
->getListCacheTags(),
],
];
// Add help text if the user can't edit group types.
if (!$user
->hasPermission('edit group types')) {
$element['#description'] = $this
->t('In order to change the group type,
please contact the content or site managers.');
}
$group_types_options = [];
$group_types_descriptions = [];
$group_types = $this->entityTypeManager
->getStorage('group_type')
->loadMultiple();
/** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
foreach ($group_types as $group_type) {
$access = $this->entityTypeManager
->getAccessControlHandler('group')
->createAccess($group_type
->id(), NULL, [], TRUE);
if ($access
->isAllowed()) {
$group_types_options[$group_type
->id()] = $group_type
->label();
$group_types_descriptions[$group_type
->id()] = [
'#description' => $group_type
->getDescription(),
];
}
$this->renderer
->addCacheableDependency($element, $access);
}
arsort($group_types_options);
$element['#options'] = $group_types_options;
// If we want to render this radio as a #type => container
// check for the $container value, this is useful for
// group edit, where we add it as a container within a field group.
if ($container) {
$element = [
'#type' => 'container',
'#parents' => [
'field_group_group_type_wrapper',
],
'#attributes' => [
'class' => [
'field--type-list-float',
'field--name-field-group-type',
'field--widget-options-buttons',
],
],
'widget' => [
'#title' => $this
->t('Group type'),
'#description' => $this
->t('In order to change the group type,
please contact the content or site managers.'),
'#field_parents' => [],
'#required' => TRUE,
'#delta' => [],
'#element_validate' => [
[
'Drupal\\Core\\Field\\Plugin\\Field\\FieldWidget\\OptionsButtonsWidget',
'validateElement',
],
],
'#key_column' => "value",
'#type' => "radios",
'#default_value' => 'open_group',
'#options' => $group_types_options,
'#after_build' => [
[
'Drupal\\Core\\Field\\Plugin\\Field\\FieldWidget\\OptionsButtonsWidget',
'afterBuild',
],
],
'#field_name' => "group_type",
'#parents' => [
'group_type',
],
'#tree' => TRUE,
],
'#weight' => 100,
];
$element['widget'] += $group_types_descriptions;
return $element;
}
return $element + $group_types_descriptions;
}