public function ConsentAgreementController::myAgreements in General Data Protection Regulation 8.2
Same name and namespace in other branches
- 8 modules/gdpr_consent/src/Controller/ConsentAgreementController.php \Drupal\gdpr_consent\Controller\ConsentAgreementController::myAgreements()
- 3.0.x modules/gdpr_consent/src/Controller/ConsentAgreementController.php \Drupal\gdpr_consent\Controller\ConsentAgreementController::myAgreements()
Render My Agreements content.
Parameters
\Drupal\Core\Session\AccountInterface $user: The user to show agreements for.
Return value
array Renderable table of user agreements.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Core\Entity\EntityMalformedException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 string reference to 'ConsentAgreementController::myAgreements'
- gdpr_consent.routing.yml in modules/
gdpr_consent/ gdpr_consent.routing.yml - modules/gdpr_consent/gdpr_consent.routing.yml
File
- modules/
gdpr_consent/ src/ Controller/ ConsentAgreementController.php, line 258
Class
- ConsentAgreementController
- Class ConsentAgreementController.
Namespace
Drupal\gdpr_consent\ControllerCode
public function myAgreements(AccountInterface $user) {
$map = $this->entityFieldManager
->getFieldMapByFieldType('gdpr_user_consent');
$agreement_storage = $this->entityTypeManager
->getStorage('gdpr_consent_agreement');
$rows = [];
foreach ($map as $entity_type => $fields) {
$field_names = array_keys($fields);
foreach ($field_names as $field_name) {
$ids = $this->entityTypeManager
->getStorage($entity_type)
->getQuery()
->condition($field_name . '.user_id', $user
->id())
->execute();
$entities = $this->entityTypeManager
->getStorage($entity_type)
->loadMultiple($ids);
foreach ($entities as $entity) {
/** @var \Drupal\gdpr_consent\Entity\ConsentAgreementInterface $agreement */
$agreement = $agreement_storage
->loadRevision($entity->{$field_name}->target_revision_id);
$link = $agreement->title->value;
if ($agreement
->access('view', $this->currentUser)) {
$link = $agreement
->toLink($agreement->title->value, 'revision')
->toString();
}
$row = [];
$row[] = [
'data' => [
'#markup' => $link,
],
];
$row[] = [
'data' => [
'#markup' => $entity->{$field_name}->date,
],
];
$rows[] = $row;
}
}
}
$header = [
'Agreement',
'Date Agreed',
];
return [
'#title' => 'Consent Agreements',
'table' => [
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
'#empty' => $this
->t('You have not yet given any consent.'),
],
];
}