Loading modules/social_features/social_group/modules/social_group_flexible_group/assets/js/form.js 0 → 100644 +66 −0 Original line number Diff line number Diff line /** * @file * Flexible group functionality. */ (function ($, Drupal) { 'use strict'; /** * @type {Drupal~behavior} */ Drupal.behaviors.fieldGroupAllowedJoinMethods = { attach: function (context, settings) { // Sets the invite only option and disables the rest. function setInviteJoinMethod(context) { $('input[name="field_group_allowed_join_method"]', context) .filter('[value="added"]') .click(); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .attr('disabled', true); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="direct"]') .attr('disabled', true); } // Initial. const groupVisibility = $('input[name="field_flexible_group_visibility"]:checked', context).val(); // If we don't have any existing values, then default to request. // If we have members selected, then make sure the other options are // disabled. if (!groupVisibility) { $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .click(); } else if (groupVisibility == 'members') { setInviteJoinMethod(context); } // On change event. $('input[name="field_flexible_group_visibility"]', context).change(function() { const groupVisibility = $('input[name="field_flexible_group_visibility"]:checked', context).val(); if (groupVisibility == 'members') { setInviteJoinMethod(context); return; } $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .attr('disabled', false); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="direct"]') .attr('disabled', false); }); } }; })(jQuery, Drupal); modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.libraries.yml +8 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,11 @@ admin: css: theme: assets/css/admin.css: {} form: js: assets/js/form.js: {} dependencies: - core/drupal - core/jquery - core/jquery.once modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module +2 −47 Original line number Diff line number Diff line Loading @@ -205,6 +205,7 @@ function social_group_flexible_group_form_alter(&$form, FormStateInterface $form $form['#after_build'][] = 'social_group_flexible_group_flexible_group_add_after_build'; $form['#attached']['library'][] = 'social_group_flexible_group/admin'; $form['#attached']['library'][] = 'social_group_flexible_group/form'; } } Loading Loading @@ -272,53 +273,7 @@ function social_group_flexible_group_flexible_group_add_after_build(array $form, ], ]; } // Add states for join method based on group visibility. // We do this for add and edit, we want to make sure if users make the // decision to choose to only show a group to it's Members, the // join method is selected to Invite only. Because there is no way // for users to join or request to join in that case. if (isset($form['field_flexible_group_visibility']['widget']['#options'], $form['field_group_allowed_join_method']['widget']['#options'])) { // If group visibility is members. Select invite-only. if (!empty($form['field_group_allowed_join_method']['widget']['added'])) { $form['field_group_allowed_join_method']['widget']['added']['#states'] = [ 'checked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } // If group visibility is members. Disable and uncheck open to join. if (!empty($form['field_group_allowed_join_method']['widget']['direct'])) { $form['field_group_allowed_join_method']['widget']['direct']['#states'] = [ 'disabled' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], 'unchecked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } // If group visibility is members. Disable and uncheck open to join. if (!empty($form['field_group_allowed_join_method']['widget']['request'])) { $form['field_group_allowed_join_method']['widget']['request']['#states'] = [ 'disabled' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], 'unchecked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } } return $form; } Loading Loading
modules/social_features/social_group/modules/social_group_flexible_group/assets/js/form.js 0 → 100644 +66 −0 Original line number Diff line number Diff line /** * @file * Flexible group functionality. */ (function ($, Drupal) { 'use strict'; /** * @type {Drupal~behavior} */ Drupal.behaviors.fieldGroupAllowedJoinMethods = { attach: function (context, settings) { // Sets the invite only option and disables the rest. function setInviteJoinMethod(context) { $('input[name="field_group_allowed_join_method"]', context) .filter('[value="added"]') .click(); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .attr('disabled', true); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="direct"]') .attr('disabled', true); } // Initial. const groupVisibility = $('input[name="field_flexible_group_visibility"]:checked', context).val(); // If we don't have any existing values, then default to request. // If we have members selected, then make sure the other options are // disabled. if (!groupVisibility) { $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .click(); } else if (groupVisibility == 'members') { setInviteJoinMethod(context); } // On change event. $('input[name="field_flexible_group_visibility"]', context).change(function() { const groupVisibility = $('input[name="field_flexible_group_visibility"]:checked', context).val(); if (groupVisibility == 'members') { setInviteJoinMethod(context); return; } $('input[name="field_group_allowed_join_method"]', context) .filter('[value="request"]') .attr('disabled', false); $('input[name="field_group_allowed_join_method"]', context) .filter('[value="direct"]') .attr('disabled', false); }); } }; })(jQuery, Drupal);
modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.libraries.yml +8 −0 Original line number Diff line number Diff line Loading @@ -3,3 +3,11 @@ admin: css: theme: assets/css/admin.css: {} form: js: assets/js/form.js: {} dependencies: - core/drupal - core/jquery - core/jquery.once
modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module +2 −47 Original line number Diff line number Diff line Loading @@ -205,6 +205,7 @@ function social_group_flexible_group_form_alter(&$form, FormStateInterface $form $form['#after_build'][] = 'social_group_flexible_group_flexible_group_add_after_build'; $form['#attached']['library'][] = 'social_group_flexible_group/admin'; $form['#attached']['library'][] = 'social_group_flexible_group/form'; } } Loading Loading @@ -272,53 +273,7 @@ function social_group_flexible_group_flexible_group_add_after_build(array $form, ], ]; } // Add states for join method based on group visibility. // We do this for add and edit, we want to make sure if users make the // decision to choose to only show a group to it's Members, the // join method is selected to Invite only. Because there is no way // for users to join or request to join in that case. if (isset($form['field_flexible_group_visibility']['widget']['#options'], $form['field_group_allowed_join_method']['widget']['#options'])) { // If group visibility is members. Select invite-only. if (!empty($form['field_group_allowed_join_method']['widget']['added'])) { $form['field_group_allowed_join_method']['widget']['added']['#states'] = [ 'checked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } // If group visibility is members. Disable and uncheck open to join. if (!empty($form['field_group_allowed_join_method']['widget']['direct'])) { $form['field_group_allowed_join_method']['widget']['direct']['#states'] = [ 'disabled' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], 'unchecked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } // If group visibility is members. Disable and uncheck open to join. if (!empty($form['field_group_allowed_join_method']['widget']['request'])) { $form['field_group_allowed_join_method']['widget']['request']['#states'] = [ 'disabled' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], 'unchecked' => [ ':input[name="field_flexible_group_visibility"]' => [ ['value' => 'members'], ], ], ]; } } return $form; } Loading