o365-2.0.3/modules/o365_profile/o365_profile.module
modules/o365_profile/o365_profile.module
<?php
/**
* @file
* Profile module file.
*/
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\user\UserInterface;
/**
* Implements hook_theme().
*/
function o365_profile_theme() {
return [
'o365_profile_block' => [
'variables' => [
'displayAvailability' => NULL,
'dataAvailability' => NULL,
'displayName' => NULL,
'data' => NULL,
'imageData' => NULL,
'givenName' => NULL,
],
'render element' => 'children',
],
'o365_profile_teams_link' => [
'variables' => [
'url' => NULL,
'text' => NULL,
'container_classes' => NULL,
'link_classes' => NULL,
'type' => NULL,
'icon' => NULL,
],
],
];
}
/**
* Implements hook_entity_extra_field_info().
*/
function o365_profile_entity_extra_field_info() {
$fields = [];
$fields['user']['user']['display']['o365_profile_teams_call'] = [
'label' => t('Call via Teams'),
'weight' => 0,
'visible' => FALSE,
];
$fields['user']['user']['display']['o365_profile_teams_chat'] = [
'label' => t('Chat via Teams'),
'weight' => 0,
'visible' => FALSE,
];
$fields['user']['user']['display']['o365_profile_teams_video'] = [
'label' => t('Video call via Teams'),
'weight' => 0,
'visible' => FALSE,
];
return $fields;
}
/**
* Implements hook_ENTITY_TYPE_view() for user entities.
*/
function o365_profile_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display) {
if ($display->getComponent('o365_profile_teams_call')) {
/** @var \Drupal\o365_profile\O365ProfileTeamsService $service */
$service = \Drupal::service('o365_profile.teams');
$call = $service->generateTeamsLink($account, 'call');
if ($call) {
$build['o365_profile_teams_call'] = $call;
}
}
if ($display->getComponent('o365_profile_teams_chat')) {
/** @var \Drupal\o365_profile\O365ProfileTeamsService $service */
$service = \Drupal::service('o365_profile.teams');
$chat = $service->generateTeamsLink($account, 'chat');
if ($chat) {
$build['o365_profile_teams_chat'] = $chat;
}
}
if ($display->getComponent('o365_profile_teams_video')) {
/** @var \Drupal\o365_profile\O365ProfileTeamsService $service */
$service = \Drupal::service('o365_profile.teams');
$video = $service->generateTeamsLink($account, 'video');
if ($video) {
$build['o365_profile_teams_video'] = $video;
}
}
}
/**
* Implements hook_o365_auth_scopes().
*/
function o365_profile_o365_auth_scopes(array &$scopes) {
$scopes[] = 'People.Read';
$scopes[] = 'Presence.Read';
$scopes[] = 'Presence.Read.All';
$scopes[] = 'profile';
$scopes[] = 'User.Read';
}
