<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pimcore / frontend-permission-toolkit-bundle example snippets
public function getPermissionResources(array $context, \Pimcore\Model\DataObject\ClassDefinition\Data $fieldDefinition): array
{
// static example for explanation
return [
['value' => 'testpermission_1', 'label' => 'Permission for test'],
['value' => 'testpermission_2', 'label' => 'Another Permission for test'],
];
}
namespace AppBundle\EventListener;
use FrontendPermissionToolkitBundle\Event\PermissionsEvent;
use Pimcore\Model\DataObject\User;
class PermissionsListener
{
public function postGetPermissions(PermissionsEvent $permissionsEvent): void
{
// Object the permissions are retrieved for
$user = $permissionsEvent->getObject();
if (!$user instanceof User) {
return;
}
// Access service methods to retrieve additional permissions and merge them
$service = $permissionsEvent->getService();
$permissions = $permissionsEvent->getPermissions();
$mergedPermissions = $permissions;
foreach ($user->getGroups() ?? [] as $userGroup) {
$userGroupPermissions = $service->getPermissions($userGroup);
$mergedPermissions = $service->mergeNestedObjectPermissions($mergedPermissions, $permissions, $userGroupPermissions);
}
// Update the permissions to return them from the service method
$permissionsEvent->setPermissions($mergedPermissions);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.