You are here

function social_group_form_group_public_group_edit_form_alter in Open Social 8.4

Same name and namespace in other branches
  1. 8 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  2. 8.2 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  3. 8.3 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  4. 8.5 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  5. 8.6 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  6. 8.7 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()
  7. 8.8 modules/social_features/social_group/social_group.module \social_group_form_group_public_group_edit_form_alter()

Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_group/social_group.module, line 43
The Social group module.

Code

function social_group_form_group_public_group_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $group = $form_state
    ->getFormObject()
    ->getEntity();
  $form['group_type'] = SocialGroupAddForm::create(\Drupal::getContainer())
    ->getGroupTypeElement();
  $form['group_type']['#default_value'] = $group
    ->bundle();

  // If user doesn't have permission to change group types disable it.
  // Or if group types can't be edited due to visibility issues.
  if (!social_group_group_type_permission_check()) {
    $form['group_type']['#disabled'] = TRUE;
  }
  else {
    $form['group_type']['#prefix'] = '<div id="group-type-result"></div>';
    $group_type_element['#ajax'] = [
      'callback' => '_social_group_inform_group_type_selection',
      'effect' => 'fade',
      'event' => 'change',
    ];
  }

  // Disable all group types that can't be edited. Because they don't have
  // a visibility.
  foreach ($form['group_type']['#options'] as $type => $label) {
    if (\Drupal::service('social_group.helper_service')
      ->getDefaultGroupVisibility($type) === NULL) {
      $form['group_type'][$type] = [
        '#disabled' => TRUE,
      ];
    }
  }
  $form['#group_children']['group_type'] = 'group_content';
}