Loading src/Entity/Form/GroupMembershipApproveForm.php +42 −4 Changes for src/Entity/Form/GroupMembershipApproveForm.php: 42 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,25 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { return $this->t('Approve'); } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $roles = $this->getGroupRoles(); if (!empty($roles)) { $form['roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#description' => $this->t('These roles will be assigned to user when membership request is approved'), '#options' => $roles ]; } return $form; } /** * {@inheritdoc} */ Loading @@ -63,10 +82,7 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { if ($result) { $this->messenger()->addStatus($this->t('Membership request approved')); // Add roles if we have them in plugin configuration. $configuration = $group_content->getContentPlugin()->getConfiguration(); $group_roles = !empty($configuration['roles']) ? array_filter($configuration['roles']) : []; $group_roles = $form_state->getValue('roles'); // Adding user to a group. $group_content->getGroup()->addMember($group_content->getEntity(), [ 'group_roles' => array_values($group_roles) Loading @@ -84,4 +100,26 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { $form_state->setRedirectUrl($this->getCancelUrl()); } /** * Get roles. * * @return array|null * List of group type's custom roles. */ protected function getGroupRoles() { $options = []; $properties = [ 'group_type' => $this->getEntity()->getGroup()->getGroupType()->id(), 'internal' => FALSE, ]; $roles = $this->entityTypeManager ->getStorage('group_role') ->loadByProperties($properties); foreach ($roles as $role) { $options[$role->id()] = $role->label(); } return $options; } } src/Plugin/GroupContentEnabler/GroupMembershipRequest.php +5 −82 Changes for src/Plugin/GroupContentEnabler/GroupMembershipRequest.php: 5 added lines, 82 removed lines. Original line number Diff line number Diff line Loading @@ -2,10 +2,7 @@ namespace Drupal\grequest\Plugin\GroupContentEnabler; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\group\Access\GroupAccessResult; use Drupal\group\Entity\GroupInterface; use Drupal\group\Entity\GroupContentInterface; Loading @@ -14,7 +11,6 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a content enabler for users. Loading @@ -26,14 +22,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * entity_type_id = "user", * pretty_path_key = "request", * reference_label = @Translation("Username"), * reference_description = @Translation("The name of the user you want to make a member"), * handlers = { * "permission_provider" = "Drupal\grequest\Plugin\GroupMembershipRequestPermissionProvider", * reference_description = @Translation("The name of the user you want to * make a member"), handlers = { * "permission_provider" = * "Drupal\grequest\Plugin\GroupMembershipRequestPermissionProvider", * }, * admin_permission = "administer members" * ) */ class GroupMembershipRequest extends GroupContentEnablerBase implements ContainerFactoryPluginInterface { class GroupMembershipRequest extends GroupContentEnablerBase { /** * Request created and waiting for administrator's response. Loading @@ -50,47 +47,6 @@ class GroupMembershipRequest extends GroupContentEnablerBase implements Containe */ const REQUEST_REJECTED = 2; /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a GroupMembershipRequest object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; } /** * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * @param array $configuration * @param string $plugin_id * @param mixed $plugin_definition * * @return static */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ Loading Loading @@ -225,40 +181,7 @@ class GroupMembershipRequest extends GroupContentEnablerBase implements Containe $form['entity_cardinality']['#disabled'] = TRUE; $form['entity_cardinality']['#description'] .= '<br /><em>' . $info . '</em>'; $roles = $this->getGroupRoles(); if (!empty($roles)) { $form['roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#description' => $this->t('These roles will be assigned to user when membership request is approved'), '#options' => $roles, '#default_value' => $this->configuration['roles'], ]; } return $form; } /** * Get roles. * * @return array|null * List of group type's custom roles. */ protected function getGroupRoles() { $options = []; $properties = [ 'group_type' => $this->getGroupTypeId(), 'internal' => FALSE, ]; $roles = $this->entityTypeManager ->getStorage('group_role') ->loadByProperties($properties); foreach ($roles as $role) { $options[$role->id()] = $role->label(); } return $options; } } Loading
src/Entity/Form/GroupMembershipApproveForm.php +42 −4 Changes for src/Entity/Form/GroupMembershipApproveForm.php: 42 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,25 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { return $this->t('Approve'); } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $roles = $this->getGroupRoles(); if (!empty($roles)) { $form['roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#description' => $this->t('These roles will be assigned to user when membership request is approved'), '#options' => $roles ]; } return $form; } /** * {@inheritdoc} */ Loading @@ -63,10 +82,7 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { if ($result) { $this->messenger()->addStatus($this->t('Membership request approved')); // Add roles if we have them in plugin configuration. $configuration = $group_content->getContentPlugin()->getConfiguration(); $group_roles = !empty($configuration['roles']) ? array_filter($configuration['roles']) : []; $group_roles = $form_state->getValue('roles'); // Adding user to a group. $group_content->getGroup()->addMember($group_content->getEntity(), [ 'group_roles' => array_values($group_roles) Loading @@ -84,4 +100,26 @@ class GroupMembershipApproveForm extends ContentEntityConfirmFormBase { $form_state->setRedirectUrl($this->getCancelUrl()); } /** * Get roles. * * @return array|null * List of group type's custom roles. */ protected function getGroupRoles() { $options = []; $properties = [ 'group_type' => $this->getEntity()->getGroup()->getGroupType()->id(), 'internal' => FALSE, ]; $roles = $this->entityTypeManager ->getStorage('group_role') ->loadByProperties($properties); foreach ($roles as $role) { $options[$role->id()] = $role->label(); } return $options; } }
src/Plugin/GroupContentEnabler/GroupMembershipRequest.php +5 −82 Changes for src/Plugin/GroupContentEnabler/GroupMembershipRequest.php: 5 added lines, 82 removed lines. Original line number Diff line number Diff line Loading @@ -2,10 +2,7 @@ namespace Drupal\grequest\Plugin\GroupContentEnabler; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\group\Access\GroupAccessResult; use Drupal\group\Entity\GroupInterface; use Drupal\group\Entity\GroupContentInterface; Loading @@ -14,7 +11,6 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a content enabler for users. Loading @@ -26,14 +22,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * entity_type_id = "user", * pretty_path_key = "request", * reference_label = @Translation("Username"), * reference_description = @Translation("The name of the user you want to make a member"), * handlers = { * "permission_provider" = "Drupal\grequest\Plugin\GroupMembershipRequestPermissionProvider", * reference_description = @Translation("The name of the user you want to * make a member"), handlers = { * "permission_provider" = * "Drupal\grequest\Plugin\GroupMembershipRequestPermissionProvider", * }, * admin_permission = "administer members" * ) */ class GroupMembershipRequest extends GroupContentEnablerBase implements ContainerFactoryPluginInterface { class GroupMembershipRequest extends GroupContentEnablerBase { /** * Request created and waiting for administrator's response. Loading @@ -50,47 +47,6 @@ class GroupMembershipRequest extends GroupContentEnablerBase implements Containe */ const REQUEST_REJECTED = 2; /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a GroupMembershipRequest object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; } /** * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * @param array $configuration * @param string $plugin_id * @param mixed $plugin_definition * * @return static */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ Loading Loading @@ -225,40 +181,7 @@ class GroupMembershipRequest extends GroupContentEnablerBase implements Containe $form['entity_cardinality']['#disabled'] = TRUE; $form['entity_cardinality']['#description'] .= '<br /><em>' . $info . '</em>'; $roles = $this->getGroupRoles(); if (!empty($roles)) { $form['roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Roles'), '#description' => $this->t('These roles will be assigned to user when membership request is approved'), '#options' => $roles, '#default_value' => $this->configuration['roles'], ]; } return $form; } /** * Get roles. * * @return array|null * List of group type's custom roles. */ protected function getGroupRoles() { $options = []; $properties = [ 'group_type' => $this->getGroupTypeId(), 'internal' => FALSE, ]; $roles = $this->entityTypeManager ->getStorage('group_role') ->loadByProperties($properties); foreach ($roles as $role) { $options[$role->id()] = $role->label(); } return $options; } }