Loading modules/o365_groups/o365_groups.module +23 −9 Original line number Diff line number Diff line Loading @@ -31,15 +31,22 @@ function o365_groups_entity_base_field_info(EntityTypeInterface $entity_type) { $fields = []; if ($entity_type->id() === 'group') { $fields['field_o365_groups_teams_id'] = BaseFieldDefinition::create('list_string') ->setLabel(t('Connected Office 365 group'))->setRevisionable(TRUE) ->setTranslatable(FALSE)->setDisplayOptions('form', [ ->setLabel(t('Connected Office 365 group')) ->setRevisionable(TRUE) ->setTranslatable(FALSE) ->setDisplayOptions('form', [ 'type' => 'select', 'weight' => 30, ])->setSettings([ ]) ->setSettings([ 'allowed_values_function' => 'o365_groups_teams_id_allowed', ])->setDisplayConfigurable('form', TRUE)->setRequired(FALSE) ->setTranslatable(TRUE)->setStorageRequired(TRUE) ->setDisplayConfigurable('view', TRUE)->setComputed(FALSE); ]) ->setDisplayConfigurable('form', TRUE) ->setRequired(FALSE) ->setTranslatable(TRUE) ->setStorageRequired(TRUE) ->setDisplayConfigurable('view', TRUE) ->setComputed(FALSE); } return $fields; } Loading Loading @@ -86,11 +93,18 @@ function o365_groups_form_group_form_alter(&$form, FormStateInterface $form_stat * @see options_allowed_values() */ function o365_groups_teams_id_allowed(BaseFieldDefinition $definition, ContentEntityInterface $entity = NULL, $cacheable) { /** @var \Drupal\o365\GraphService $graphService */ $graphService = \Drupal::service('o365.graph'); if ($graphService && $graphService->getCurrentUserId()) { /** @var \Drupal\o365_groups\GroupsService $groupsService */ $groupsService = \Drupal::service('o365_groups.groups'); return $groupsService->getGroupsFromTeams(); } return []; } /** * Implements hook_o365_auth_scopes(). */ Loading modules/o365_groups/src/GroupsService.php +26 −22 Original line number Diff line number Diff line Loading @@ -96,13 +96,14 @@ class GroupsService { protected function getTeamsFromGraph($endpoint = FALSE) { $cid = 'getTeamsFromGraph::' . $this->currentUser->id(); $cache = $this->cacheBackend->get($cid); $teams = []; if (!$cache) { try { if (!$endpoint) { $endpoint = $this->getTeamsEndpoint; } $teams = []; $data = $this->o365Graph->getGraphData($endpoint, 'GET', FALSE, FALSE, Group::class); if ($data) { Loading @@ -124,8 +125,11 @@ class GroupsService { $expireDate = strtotime('+4 hours'); $this->cacheBackend->set($cid, $teams, $expireDate); } finally { $this->teams = $teams; } } else { $this->teams = $cache->data; } Loading Loading
modules/o365_groups/o365_groups.module +23 −9 Original line number Diff line number Diff line Loading @@ -31,15 +31,22 @@ function o365_groups_entity_base_field_info(EntityTypeInterface $entity_type) { $fields = []; if ($entity_type->id() === 'group') { $fields['field_o365_groups_teams_id'] = BaseFieldDefinition::create('list_string') ->setLabel(t('Connected Office 365 group'))->setRevisionable(TRUE) ->setTranslatable(FALSE)->setDisplayOptions('form', [ ->setLabel(t('Connected Office 365 group')) ->setRevisionable(TRUE) ->setTranslatable(FALSE) ->setDisplayOptions('form', [ 'type' => 'select', 'weight' => 30, ])->setSettings([ ]) ->setSettings([ 'allowed_values_function' => 'o365_groups_teams_id_allowed', ])->setDisplayConfigurable('form', TRUE)->setRequired(FALSE) ->setTranslatable(TRUE)->setStorageRequired(TRUE) ->setDisplayConfigurable('view', TRUE)->setComputed(FALSE); ]) ->setDisplayConfigurable('form', TRUE) ->setRequired(FALSE) ->setTranslatable(TRUE) ->setStorageRequired(TRUE) ->setDisplayConfigurable('view', TRUE) ->setComputed(FALSE); } return $fields; } Loading Loading @@ -86,11 +93,18 @@ function o365_groups_form_group_form_alter(&$form, FormStateInterface $form_stat * @see options_allowed_values() */ function o365_groups_teams_id_allowed(BaseFieldDefinition $definition, ContentEntityInterface $entity = NULL, $cacheable) { /** @var \Drupal\o365\GraphService $graphService */ $graphService = \Drupal::service('o365.graph'); if ($graphService && $graphService->getCurrentUserId()) { /** @var \Drupal\o365_groups\GroupsService $groupsService */ $groupsService = \Drupal::service('o365_groups.groups'); return $groupsService->getGroupsFromTeams(); } return []; } /** * Implements hook_o365_auth_scopes(). */ Loading
modules/o365_groups/src/GroupsService.php +26 −22 Original line number Diff line number Diff line Loading @@ -96,13 +96,14 @@ class GroupsService { protected function getTeamsFromGraph($endpoint = FALSE) { $cid = 'getTeamsFromGraph::' . $this->currentUser->id(); $cache = $this->cacheBackend->get($cid); $teams = []; if (!$cache) { try { if (!$endpoint) { $endpoint = $this->getTeamsEndpoint; } $teams = []; $data = $this->o365Graph->getGraphData($endpoint, 'GET', FALSE, FALSE, Group::class); if ($data) { Loading @@ -124,8 +125,11 @@ class GroupsService { $expireDate = strtotime('+4 hours'); $this->cacheBackend->set($cid, $teams, $expireDate); } finally { $this->teams = $teams; } } else { $this->teams = $cache->data; } Loading