{"id":845,"date":"2015-10-02T17:43:58","date_gmt":"2015-10-02T15:43:58","guid":{"rendered":"http:\/\/webpiraten.de\/?p=845"},"modified":"2015-10-02T17:43:58","modified_gmt":"2015-10-02T15:43:58","slug":"symfony-sonata-acl-neue-eintraege-die-nicht-im-sonata-erzeugt-werden-haben-keine-rechte","status":"publish","type":"post","link":"https:\/\/webpiraten.de\/index.php\/frameworks\/symfony-sonata-acl-neue-eintraege-die-nicht-im-sonata-erzeugt-werden-haben-keine-rechte\/","title":{"rendered":"Symfony Sonata ACL &#8211; neue Eintr\u00e4ge die nicht im Sonata erzeugt werden haben keine Rechte"},"content":{"rendered":"<p>Um in Symfony Sonata die ACL auch mit Eintr\u00e4gen zu nutzen, die durch ein Frontend oder im Hintergrund erzeugt werden, ohne den Sonatakontext, muss man den ACL Eintrag selbst erstellen. Dazu kann man einen EntityEventListener installieren und im postPersist Event folgendes tun:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n    public function postPersist(LifecycleEventArgs $args)\r\n    {\r\n        $this-&gt;addAcl($args);\r\n    }\r\n\r\n    protected function addAcl(LifecycleEventArgs $args)\r\n    {\r\n        $entity = $args-&gt;getEntity();\r\n\r\n        $adminSecurityHandler = $this-&gt;container-&gt;get('sonata.admin.security.handler');\r\n\r\n        $adminPool  = $this-&gt;container-&gt;get('sonata.admin.pool');\r\n        $admin      = $adminPool-&gt;getAdminByClass(get_class($entity));\r\n\r\n        if (null !== $admin) {\r\n            $objectIdentity = ObjectIdentity::fromDomainObject($entity);\r\n            $acl = $adminSecurityHandler-&gt;getObjectAcl($objectIdentity);\r\n            if (is_null($acl)) {\r\n                $acl = $adminSecurityHandler-&gt;createAcl($objectIdentity);\r\n            }\r\n            $adminSecurityHandler-&gt;addObjectClassAces($acl, $adminSecurityHandler-&gt;buildSecurityInformation($admin));\r\n            $adminSecurityHandler-&gt;updateAcl($acl);\r\n        }\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Um in Symfony Sonata die ACL auch mit Eintr\u00e4gen zu nutzen, die durch ein Frontend oder im Hintergrund erzeugt werden, ohne den Sonatakontext, muss man den ACL Eintrag selbst erstellen. Dazu kann man einen EntityEventListener installieren und im postPersist Event folgendes tun: public function postPersist(LifecycleEventArgs $args) { $this-&gt;addAcl($args); } protected function addAcl(LifecycleEventArgs $args) { $entity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[543,3,5,607,567],"tags":[],"class_list":["post-845","post","type-post","status-publish","format-standard","hentry","category-cms-systeme","category-frameworks","category-php","category-sonata","category-symfony2"],"_links":{"self":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/comments?post=845"}],"version-history":[{"count":1,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/845\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/845\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/media?parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/categories?post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/tags?post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}