{"action":"created","issue":{"url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/82","labels_url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/82/comments","events_url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/82/events","html_url":"https://github.com/symfony2admingenerator/GeneratorBundle/issues/82","id":58106653,"number":82,"title":"credentials in field context","user":{"login":"lucarnu","id":1324603,"avatar_url":"https://avatars.githubusercontent.com/u/1324603?v=3","gravatar_id":"","url":"https://api.github.com/users/lucarnu","html_url":"https://github.com/lucarnu","followers_url":"https://api.github.com/users/lucarnu/followers","following_url":"https://api.github.com/users/lucarnu/following{/other_user}","gists_url":"https://api.github.com/users/lucarnu/gists{/gist_id}","starred_url":"https://api.github.com/users/lucarnu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucarnu/subscriptions","organizations_url":"https://api.github.com/users/lucarnu/orgs","repos_url":"https://api.github.com/users/lucarnu/repos","events_url":"https://api.github.com/users/lucarnu/events{/privacy}","received_events_url":"https://api.github.com/users/lucarnu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/milestones/2","html_url":"https://github.com/symfony2admingenerator/GeneratorBundle/milestones/v2.0-stable","labels_url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/milestones/2/labels","id":902564,"number":2,"title":"v2.0-stable","description":"Things to do before releasing `v2.0` stable release","creator":{"login":"loostro","id":1419884,"avatar_url":"https://avatars.githubusercontent.com/u/1419884?v=3","gravatar_id":"","url":"https://api.github.com/users/loostro","html_url":"https://github.com/loostro","followers_url":"https://api.github.com/users/loostro/followers","following_url":"https://api.github.com/users/loostro/following{/other_user}","gists_url":"https://api.github.com/users/loostro/gists{/gist_id}","starred_url":"https://api.github.com/users/loostro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loostro/subscriptions","organizations_url":"https://api.github.com/users/loostro/orgs","repos_url":"https://api.github.com/users/loostro/repos","events_url":"https://api.github.com/users/loostro/events{/privacy}","received_events_url":"https://api.github.com/users/loostro/received_events","type":"User","site_admin":false},"open_issues":22,"closed_issues":6,"state":"open","created_at":"2014-12-13T11:33:03Z","updated_at":"2015-03-30T23:01:42Z","due_on":"2015-04-29T22:00:00Z","closed_at":null},"comments":4,"created_at":"2015-02-18T18:22:08Z","updated_at":"2015-04-03T11:13:18Z","closed_at":null,"body":"Hi!\r\n\r\nActually I want to use credentials in field context:\r\n```\r\n  fields:\r\n    myField:\r\n      credentials: 'hasRole(\"ROLE_USER\")'\r\n```\r\n\r\nAfter implementation of\r\n\r\n```\r\nparams:\r\n    fields:\r\n        username:\r\n            credentials: 'hasRole(\"ROLE_ADMIN\")'\r\n            label:            admin.user.fields.username\r\n\r\n```\r\n every try gives an error:\r\n\r\n```\r\nTwig_Error_Runtime in classes.php line 4696: \r\nAn exception has been thrown during the rendering of a template \r\n(\"Could not set option \"credentials\" on \"username\" column in \"User\" list builder.\")\r\n in \"ListBuilderAction.php.twig\" at line 10.\r\n```\r\n\r\nAfter research, it seems to me, that field driven usage of credentials not is implemented. \r\nDo I am wrong?\r\n\r\nIf not, I like to think ahead:\r\n\r\nGroups can be assigned to a field. So my idea would be to define groups in configuration file like:\r\n\r\n```\r\nparams:\r\n    groups:\r\n        Admin:\r\n            credentials: 'hasRole(\"ROLE_ADMIN\")'\r\n        User:\r\n            credentials: 'hasRole(\"ROLE_USER\")'\r\n```\r\nwith usage\r\n\r\n```\r\nparams:\r\n    fields:\r\n        username:\r\n            groups:           [\"User\", \"Admin\"]\r\n            label:            admin.user.fields.username\r\n```\r\n\r\nSo in this case we need to change the getGroups method on EditController/NewController/ShowController like this:\r\n``` EditBuilderAction.php.twig ```\r\n```\r\n    /**\r\n     * Get groups.\r\n     *\r\n     * @param \\{{ model }} ${{ builder.ModelClass }}\r\n     * @return array\r\n     */\r\n    protected function getGroups(\\{{ model }} ${{ builder.ModelClass }})\r\n    {\r\n\r\n        {% if true == builder.getVariable(\"groups\") %}\r\n        //ensure that it is not empty\r\n        $groups = array(\"GROUPS_ENABLED\");\r\n            {% for key, group in builder.getVariable(\"groups\") %}\r\n                {% if group.credentials is defined %}\r\n\r\n        if ($this->evaluate('{{group.credentials}}', ${{ builder.ModelClass }})) {\r\n            $groups[] = \"{{key}}\";\r\n        }\r\n\r\n                {% else %}\r\n\r\n        $groups[] = \"{{key}}\";\r\n\r\n                {% endif %}\r\n            {% endfor %}\r\n        {% else %}\r\n        $groups = array();\r\n        {% endif %}\r\n\r\n        return $groups;\r\n    }\r\n```\r\n\r\nThis would produce:\r\n``` ~\\EditController.php ```\r\n```\r\n    protected function getGroups(UserBundle\\Entity\\User $User)\r\n    { \r\n        $groups = array(\"GROUPS_ENABLED\");\r\n                            \r\n        if ($this->evaluate('hasRole(\"ROLE_ADMIN\")', $User)) {\r\n            $groups[] = \"Admin\";\r\n        }\r\n                                           \r\n        if ($this->evaluate('hasRole(\"ROLE_USER\")', $User)) {\r\n            $groups[] = \"User\";\r\n        }\r\n                                    \r\n        return $groups;\r\n    }\r\n\r\n```\r\n\r\nWhat do you think about that?"},"comment":{"url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/comments/89257353","html_url":"https://github.com/symfony2admingenerator/GeneratorBundle/issues/82#issuecomment-89257353","issue_url":"https://api.github.com/repos/symfony2admingenerator/GeneratorBundle/issues/82","id":89257353,"user":{"login":"loostro","id":1419884,"avatar_url":"https://avatars.githubusercontent.com/u/1419884?v=3","gravatar_id":"","url":"https://api.github.com/users/loostro","html_url":"https://github.com/loostro","followers_url":"https://api.github.com/users/loostro/followers","following_url":"https://api.github.com/users/loostro/following{/other_user}","gists_url":"https://api.github.com/users/loostro/gists{/gist_id}","starred_url":"https://api.github.com/users/loostro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loostro/subscriptions","organizations_url":"https://api.github.com/users/loostro/orgs","repos_url":"https://api.github.com/users/loostro/repos","events_url":"https://api.github.com/users/loostro/events{/privacy}","received_events_url":"https://api.github.com/users/loostro/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T11:13:18Z","updated_at":"2015-04-03T11:13:18Z","body":"@lucarnu join our [gitter chat](https://gitter.im/symfony2admingenerator/GeneratorBundle) if you need to discuss PRs or just want to chat :)"}}