How to create new permission that can show my custom menu panel in pimcore plugin?

I created new custom panel using my custom pimcore plugin . i need to create new
custom permission in role . so when this permission is checked. my panel is show.


I created new role for this and need to create custom permission for show this panel.
Please help me

I got the answer.
we can create custom permision in plugin installer using this code.

private $permissionsToInstall = [
    'custom_permision_name',
   
];
 private function installPermissions()
  {
    foreach ($this->permissionsToInstall as $permission) {
        $definition = Permission\Definition::getByKey($permission);

        if ($definition) {
            $this->outputWriter->write(sprintf(
                '     <comment>WARNING:</comment> Skipping permission "%s" as it already exists',
                $permission
            ));

            continue;
        }

        try {
            Permission\Definition::create($permission);
        } catch (\Throwable $e) {
            throw new AbortMigrationException(sprintf(
                'Failed to create permission "%s"',
                $permission
            ));
        }
    }
}

and u can use this in your js to hide and show
user.isAllowed(‘custom_permision_name’);
like that

You also could just simply add a entry into the database table users_permission_definitions

BR
Christian

1 Like