DataPolicy.php in Open Social 8.2
File
modules/custom/social_gdpr/src/Controller/DataPolicy.php
View source
<?php
namespace Drupal\social_gdpr\Controller;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Url;
use Drupal\data_policy\Controller\DataPolicy as DataPolicyBase;
class DataPolicy extends DataPolicyBase {
public function entityOverviewAccess() {
$access = parent::entityOverviewAccess();
if ($access
->isForbidden() && $this
->currentUser()
->hasPermission('edit data policy')) {
$access = AccessResult::allowed();
}
return $access;
}
public function revisionOverviewTitle($data_policy_revision) {
$data_policy = $this
->entityTypeManager()
->getStorage('data_policy')
->loadRevision($data_policy_revision);
return $this
->t('Revision from %date', [
'%date' => $this
->dateFormatter()
->format($data_policy
->getRevisionCreationTime()),
]);
}
public function revisionsOverviewPage() {
$build = parent::revisionsOverviewPage();
$routes = [
'view' => 'social_gdpr.data_policy.revision',
'edit' => 'social_gdpr.data_policy.revision_edit',
'delete' => 'social_gdpr.data_policy.revision_delete',
];
foreach ($build['data_policy_revisions_table']['#rows'] as &$row) {
foreach ($row[1]['data']['#links'] as $operation => &$link) {
$url =& $link['url'];
if ($operation == 'revert') {
if ($url
->getRouteName() == 'entity.data_policy.revision_revert') {
$route_name = 'social_gdpr.data_policy.revision_revert';
}
else {
$route_name = 'social_gdpr.data_policy.translation_revert';
}
$link['url'] = Url::fromRoute($route_name, $url
->getRouteParameters());
$link['attributes'] = [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'dialogClass' => 'social-dialog',
'title' => '',
'width' => 360,
]),
];
}
if (isset($routes[$operation])) {
$link['url'] = Url::fromRoute($routes[$operation], $link['url']
->getRouteParameters());
}
}
$url =& $row[1]['data']['#links']['view']['url'];
$parameters = $url
->getRouteParameters();
$row = [
'data' => $row,
'class' => [
'revision-' . $parameters['data_policy_revision'],
],
];
}
return $build;
}
}