You are here

function social_group_flexible_group_form_alter in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module \social_group_flexible_group_form_alter()
  2. 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module \social_group_flexible_group_form_alter()
  3. 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module \social_group_flexible_group_form_alter()
  4. 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module \social_group_flexible_group_form_alter()

Implements hook_form_alter().

File

modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module, line 70
The Social Group Flexible Group module.

Code

function social_group_flexible_group_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Exposed Filter block on the all-groups overview and search.
  if ($form['#id'] === 'views-exposed-form-newest-groups-page-all-groups' || $form['#id'] === 'views-exposed-form-search-groups-page-no-value' || $form['#id'] === 'views-exposed-form-search-groups-page') {

    // Update filter values so it matches the join methods in the popover.
    if (!empty($form['field_group_allowed_join_method'])) {
      if (array_key_exists('added', $form['field_group_allowed_join_method']['#options'])) {
        $form['field_group_allowed_join_method']['#options']['added'] = t('Invite only');
      }
      if (array_key_exists('direct', $form['field_group_allowed_join_method']['#options'])) {
        $form['field_group_allowed_join_method']['#options']['direct'] = t('Open to join');
      }
      if (array_key_exists('request', $form['field_group_allowed_join_method']['#options'])) {
        $form['field_group_allowed_join_method']['#options']['request'] = t('Request to join');
      }
    }

    // Add states so this is only available when flexible groups is checked.
    // Could be hidden when only flexible groups is enabled, so check that.
    // @TODO remove this once everything is migrated to flexible groups.
    if (!empty($form['field_group_allowed_join_method']) && !empty($form['type']['#options']) && $form['type']['#type'] !== 'hidden') {
      $form['field_group_allowed_join_method']['#states'] = [
        'visible' => [
          ':input[name="type"]' => [
            'value' => 'flexible_group',
          ],
        ],
      ];
    }
  }
}