Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

Checking if user has permission to edit content in eZ Platform using the API

eZ Platform is a Full Stack Symfony based Content Management System (CMS). It adds a content repository and other features that allow users to create content. This is controlled by a sophisticated permissions system that allows finegrained control.

Developers use standard services to interact with the repository. There are plenty of good examples of this in the CookBookBundle. One thing that is not covered by the examples in the bundle is how to check if a user has permission to do a certain function.

You can do this easily by using the PermissionResolver from the repository, for example:

$content = $contentService->loadContent(52);
$canEdit = $permissionResolver->canUser('content','edit',$content);

    echo "Logged in user can edit object " . $content->getName();
} else {
    echo "Logged in user can't edit object " . $content->getName();

Written by Jani Tarvainen on Thursday July 13, 2017
Permalink -

« Using a eZ Platform / eZ Publish 5.4 for local development without images - Migrating eZ Platform Landing Pages and Form Builder Forms »