public static function moduleHelper::ProcessGroupContentUpdate in Rocket.Chat 8.2
Parameters
\Drupal\group\Entity\GroupContent $entity:
string $action:
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
3 calls to moduleHelper::ProcessGroupContentUpdate()
- rocket_chat_group_group_content_delete in modules/
rocket_chat_group/ rocket_chat_group.module - Implements hook_ENTITY_TYPE_delete().
- rocket_chat_group_group_content_insert in modules/
rocket_chat_group/ rocket_chat_group.module - Implements hook_ENTITY_TYPE_insert().
- rocket_chat_group_group_content_update in modules/
rocket_chat_group/ rocket_chat_group.module - Implements hook_ENTITY_TYPE_update().
File
- modules/
rocket_chat_group/ src/ RocketChat/ moduleHelper.php, line 40
Class
Namespace
Drupal\rocket_chat_group\RocketChatCode
public static function ProcessGroupContentUpdate(GroupContent $entity, $action = "Unknown") {
$groupSelected = $entity
->getGroup();
$groupOwner = $entity
->getOwner();
$targetUserFields = $entity
->getFields(FALSE);
$targetGroupFields = $groupSelected
->getFields(FALSE);
$userRef = $targetUserFields['entity_id']
->getValue();
$userRefEntity = Drupal::entityTypeManager()
->getStorage('user')
->load($userRef[0]['target_id']);
$groupEntity = $entity
->getGroup();
$groupType = $groupEntity
->getGroupType();
$groupEntitytypeId = $groupType
->id();
$channel = new Channel();
$rcState = new Drupal8State(Drupal::service('state'));
$chatGroupOwner = new RocketchatUser($rcState, $groupOwner
->getAccountName(), $groupOwner
->getEmail(), $groupOwner
->getDisplayName());
$channel
->setOwner($chatGroupOwner);
$fieldMachineName = self::extractChannelMachineName($groupSelected);
$channelName = NULL;
if (!empty($fieldMachineName) && isset($targetGroupFields[$fieldMachineName])) {
$test[] = $targetGroupFields[$fieldMachineName]
->getValue();
foreach ($targetGroupFields[$fieldMachineName]
->getValue() as $channelDetails) {
foreach ($channelDetails as $channelName) {
$channel
->setChannelName($channelName);
break;
}
break;
}
self::updateChannelType($groupEntitytypeId, $channel);
}
$apiConfig = new Drupal8Config(Drupal::configFactory(), Drupal::moduleHandler(), Drupal::state(), Drupal::messenger());
$apiClient = new ApiClient($apiConfig);
switch ($action) {
default:
self::addLogEntry("no action taken on [{$action}] for Group [" . $groupSelected
->id() . "]");
break;
case "insert":
// Inserting something into a group content.
$channel
->getChannelProxy($apiClient);
$channel
->getChannelMembers($apiClient);
/** @var \Drupal\user\Entity\User[] $GroupMembers */
$GroupMembers = [];
foreach ($userRef as $target) {
$targetUser = Drupal::entityTypeManager()
->getStorage('user')
->load($target['target_id']);
if (!empty($targetUser)) {
$GroupMembers[] = $targetUser;
}
unset($targetUser);
}
foreach ($GroupMembers as $groupMember) {
$rcUser = new RocketchatUser($rcState, $groupMember
->getAccountName(), $groupMember
->getEmail(), $groupMember
->getDisplayName());
$rcUser
->getUserProxy($apiClient);
$channel
->addMember($apiClient, $rcUser);
}
$channels = new Channels($rcState, $apiClient);
$channels
->refreshCache(TRUE);
return;
break;
case "delete":
// Inserting something into a group content.
$channel
->getChannelProxy($apiClient);
$channel
->getChannelMembers($apiClient);
/** @var \Drupal\user\Entity\User[] $GroupMembers */
$GroupMembers = [];
foreach ($userRef as $target) {
$targetUser = Drupal::entityTypeManager()
->getStorage('user')
->load($target['target_id']);
if (!empty($targetUser)) {
$GroupMembers[] = $targetUser;
}
unset($targetUser);
}
foreach ($GroupMembers as $groupMember) {
$rcUser = new RocketchatUser($rcState, $groupMember
->getAccountName(), $groupMember
->getEmail(), $groupMember
->getDisplayName());
$rcUser
->getUserProxy($apiClient);
// $channel;
$removed = $channel
->removeMember($apiClient, $rcUser);
//TODO log result of removal
}
$channels = new Channels($rcState, $apiClient);
$channels
->refreshCache(TRUE);
return;
break;
}
if ($apiClient
->isLoggedIn()) {
$channelProxy = $channel
->getChannelProxy($apiClient);
$rcState = new Drupal8State(Drupal::state());
$user = new RocketchatUser($rcState, $userRefEntity
->getAccountName(), $userRefEntity
->getEmail(), $userRefEntity
->getDisplayName());
$user
->getUserProxy($apiClient);
$channel
->addMember($apiClient, $user);
$users = [];
$usersProxy = new Users($rcState, $apiClient);
$users = $usersProxy
->getCache();
$channel
->getChannelType();
}
else {
Drupal::messenger()
->addWarning("Unable to do anything before you login to Rocket.Chat.");
}
}