Skip to content
Snippets Groups Projects

Issue #3188270: Add support for "Group creator must complete their membership"

Merged Jaap Jan Koster requested to merge issue/group_flex-3188270:3188270-add-support-for into 1.x
1 file
+ 97
20
Compare changes
  • Side-by-side
  • Inline
+ 97
20
@@ -40,6 +40,7 @@ function group_flex_form_group_form_alter(&$form, FormStateInterface $form_state
if ($group_type) {
$group_flex_enable = $group_type->getThirdPartySetting('group_flex', 'group_flex_enabler', 0);
if ($group_flex_enable === 1) {
$add_submit_handler = FALSE;
/** @var \Drupal\group_flex\Plugin\GroupVisibilityManager $visibilityPluginManager */
$visibilityPluginManager = \Drupal::service('plugin.manager.group_visibility');
$visibilityPlugins = $visibilityPluginManager->getAllAsArray();
@@ -79,7 +80,7 @@ function group_flex_form_group_form_alter(&$form, FormStateInterface $form_state
}
}
// Add submit handler.
$form['actions']['submit']['#submit'][] = '_group_flex_form_group_visibility_form_submit';
$add_submit_handler = TRUE;
}
else {
/** @var \Drupal\group_flex\Plugin\GroupVisibilityBase $pluginInstance */
@@ -159,9 +160,11 @@ function group_flex_form_group_form_alter(&$form, FormStateInterface $form_state
}
// Add submit handler.
$form['actions']['submit']['#submit'][] = '_group_flex_form_group_joining_method_form_submit';
$add_submit_handler = TRUE;
}
if ($add_submit_handler === TRUE) {
$form['actions']['submit']['#submit'][] = '_group_flex_form_group_step1_form_submit';
}
}
}
}
@@ -169,31 +172,105 @@ function group_flex_form_group_form_alter(&$form, FormStateInterface $form_state
/**
* Save the visibility options for the group.
*/
function _group_flex_form_group_visibility_form_submit($form, FormStateInterface $form_state) {
$group_visibility = $form_state->getValue('group_visibility', NULL);
if ($group_visibility !== NULL) {
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $form_state->getFormObject()->getEntity();
if ($group) {
/** @var \Drupal\group_flex\GroupFlexGroupSaver $group_flex_group_saver */
$group_flex_group_saver = \Drupal::service('group_flex.group_saver');
$group_flex_group_saver->saveGroupVisibility($group, $group_visibility);
function _group_flex_form_group_step1_form_submit($form, FormStateInterface $form_state) {
// Create an array of group flex settings.
$group_flex_settings = [
'visibility' => $form_state->getValue('group_visibility', NULL),
'joining_methods' => $form_state->getValue('group_joining_methods', NULL),
];
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $form_state->getFormObject()->getEntity();
$group_type = $group->getGroupType();
foreach ($group_flex_settings as $key => $value) {
if ($value !== NULL) {
if ($group && $group->id()) {
/** @var \Drupal\group_flex\GroupFlexGroupSaver $group_flex_group_saver */
$group_flex_group_saver = \Drupal::service('group_flex.group_saver');
switch ($key) {
case 'visibility':
$group_flex_group_saver->saveGroupVisibility($group, $value);
break;
case 'joining_methods':
$group_flex_group_saver->saveGroupJoiningMethods($group, $value);
break;
}
}
else {
$wizard_id = 'group_creator';
if ($form_state->get('group_wizard') && $form_state->get('group_wizard_id') === 'group_creator') {
// See if the group type is configured to ask the creator to fill out
// membership details. Also pass this info to the private temp store.
if ($group_type->creatorMustCompleteMembership()) {
$privateTempStore = \Drupal::service('tempstore.private');
$store = $privateTempStore->get($wizard_id . '_flex');
$store_id = $form_state->get('store_id');
$store->set("$store_id:$key", $value);
}
}
}
}
}
}
/**
* Save the joining methods for the group.
* Implements hook_form_BASE_FORM_ID_alter().
*
* Alters the step 2 form of a group creation. This is needed to support
* creatorMustCompleteMembership on the Group Type.
*/
function group_flex_form_group_content_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$wizard_id = 'group_creator';
if ($form_state->get('group_wizard') && $form_state->get('group_wizard_id') === $wizard_id) {
$store_id = $form_state->get('store_id');
$privateTempStore = \Drupal::service('tempstore.private');
$store = $privateTempStore->get($wizard_id);
$group_type = \Drupal::entityTypeManager()->getStorage('group_type')->load($store_id);
// See if the group type is configured to ask the creator to fill out their
// membership details. Also pass this info to the form state.
if ($group_type && $group_type->creatorMustCompleteMembership()) {
if ($store->get("$store_id:step") === 2) {
$form['actions']['submit']['#submit'][] = '_group_flex_form_group_step2_form_submit';
}
}
}
}
/**
* Save the store values of the group type.
*
* @param $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function _group_flex_form_group_joining_method_form_submit($form, FormStateInterface $form_state) {
$group_visibility = $form_state->getValue('group_joining_methods', NULL);
if ($group_visibility !== NULL) {
/** @var \Drupal\group\Entity\GroupInterface $group */
$group = $form_state->getFormObject()->getEntity();
if ($group) {
function _group_flex_form_group_step2_form_submit($form, FormStateInterface $form_state) {
$privateTempStore = \Drupal::service('tempstore.private');
$store = $privateTempStore->get('group_creator_flex');
$store_id = $form_state->get('store_id');
$group_content_entity = $form_state->getFormObject()->getEntity();
$group = $group_content_entity->getGroup();
$group_flex_settings = ['visibility', 'joining_methods'];
foreach ($group_flex_settings as $key) {
if ($value = $store->get("$store_id:$key")) {
/** @var \Drupal\group_flex\GroupFlexGroupSaver $group_flex_group_saver */
$group_flex_group_saver = \Drupal::service('group_flex.group_saver');
$group_flex_group_saver->saveGroupJoiningMethods($group, $group_visibility);
switch ($key) {
case 'visibility':
$group_flex_group_saver->saveGroupVisibility($group, $value);
break;
case 'joining_methods':
$group_flex_group_saver->saveGroupJoiningMethods($group, $value);
break;
}
$store->delete("$store_id:$key");
}
}
}
Loading