public function getGroupTypeElement() {
    $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;
    return $element + $group_types_descriptions;
  }
public function getGroupTypeElement() {
    $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;
    return $element + $group_types_descriptions;
  }
public function getGroupTypeElement ( ) { $ 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 ; return $ element + $ group_types_descriptions ; }
Get the group type element.

Note this element is also used in the edit group form.

@return array
Returns an array containing the group type element and descriptions.
Get the group type element .