-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new task for fetching the UUID of the graphql_consumer. This
UUID is used while calling the GraphQL API.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* DPL consumers module. | ||
*/ | ||
|
||
use Drupal\dpl_consumers\DplGraphqlConsumersConstants; | ||
|
||
/** | ||
* Function is used for printing out the consumer credentials to the console. | ||
*/ | ||
function dpl_consumers_print_consumer_credentials() { | ||
$graphql_consumer_client_id = DplGraphqlConsumersConstants::GRAPHQL_CONSUMER_CLIENT_ID; | ||
$consumer_uuid = dpl_consumers_get_consumer_uuid($graphql_consumer_client_id); | ||
print_r('Consumer UUID: ' . $consumer_uuid); | ||
} | ||
|
||
/** | ||
* Get consumer by Client ID. | ||
* | ||
* @return string | ||
* The consumer UUID. | ||
*/ | ||
function dpl_consumers_get_consumer_uuid(string $client_id): string { | ||
try { | ||
$consumer = \Drupal::entityTypeManager() | ||
->getStorage('consumer') | ||
->loadByProperties(['client_id' => $client_id]); | ||
|
||
if (!empty($consumer)) { | ||
$consumer = reset($consumer); | ||
return $consumer->uuid(); | ||
} | ||
} | ||
catch (\Exception $e) { | ||
\Drupal::logger('dpl_consumers')->error($e->getMessage()); | ||
return 'Consumer not found.'; | ||
} | ||
} |