Privilege example

throw new Enlight_Exception(sprintf('Resource "%s" already exists', $resourceName));
        }

        $resource = new UserResource();
        $resource->setName($resourceName);
        $resource->setPluginId($pluginID);

        if (!empty($privileges)) {
            $privilegeObjects = [];

            foreach ($privileges as $name) {
                $privilege = new Privilege();
                $privilege->setName($name);
                $privilege->setResource($resource);

                $this->em->persist($privilege);

                $privilegeObjects[] = $privilege;
            }

            $resource->setPrivileges(new ArrayCollection($privilegeObjects));
        }

        
$this->manager->flush($item);
    }

    private function addPrivilegeIfMissing(AclResource $resource, string $name): void
    {
        foreach ($resource->getPrivileges() as $privilege) {
            if ($privilege->getName() === $name) {
                return;
            }
        }

        $newPriv = new Privilege();
        $newPriv->setName($name);
        $newPriv->setResource($resource);
        $this->manager->persist($newPriv);

        $resource->getPrivileges()->add($newPriv);
    }
}
'success' => true,
            'data' => $data,
        ]);
    }

    /** * Event listener method of the user manager backend module, which is fired * when the user wants to create a new resource. */
    public function savePrivilegeAction()
    {
        $privilege = new Privilege();
        $data = $this->Request()->getParams();
        $privilege->fromArray($data);

        $this->modelManager->persist($privilege);
        $this->modelManager->flush();

        $data = $this->modelManager->toArray($privilege);

        $this->View()->assign([
            'success' => true,
            'data' => $data,
        ]);
Home | Imprint | This part of the site doesn't use cookies.