{"action":"created","comment":{"url":"https://api.github.com/repos/orocrm/platform/pulls/comments/52335104","id":52335104,"diff_hunk":"@@ -44,66 +55,110 @@ public function __construct(\n      */\n     public function onNavigationConfigure(ConfigureMenuEvent $event)\n     {\n-        $menu     = $event->getMenu();\n-        $children = array();\n-\n-        $entitiesMenuItem = $menu->getChild('system_tab')->getChild('entities_list');\n-        if ($entitiesMenuItem) {\n-            /** @var ConfigProvider $entityConfigProvider */\n-            $entityConfigProvider = $this->configManager->getProvider('entity');\n-\n-            /** @var ConfigProvider $entityExtendProvider */\n-            $entityExtendProvider = $this->configManager->getProvider('extend');\n-\n-            $extendConfigs = $entityExtendProvider->getConfigs();\n-\n-            foreach ($extendConfigs as $extendConfig) {\n-                if ($this->checkAvailability($extendConfig)) {\n-                    $config = $entityConfigProvider->getConfig($extendConfig->getId()->getClassname());\n-                    if (!class_exists($config->getId()->getClassName()) ||\n-                        !$this->securityFacade->hasLoggedUser() ||\n-                        !$this->securityFacade->isGranted('VIEW', 'entity:' . $config->getId()->getClassName())\n-                    ) {\n-                        continue;\n-                    }\n-\n-                    $children[$config->get('label')] = array(\n-                        'label'   => $this->translator->trans($config->get('label')),\n-                        'options' => array(\n-                            'route'           => 'oro_entity_index',\n-                            'routeParameters' => array(\n-                                'entityName' => str_replace('\\\\', '_', $config->getId()->getClassName())\n-                            ),\n-                            'extras'          => array(\n-                                'safe_label' => true,\n-                                'routes'     => array('oro_entity_*')\n-                            ),\n-                        )\n-                    );\n-                }\n+        $entitiesMenuItem = $event->getMenu()->getChild('system_tab')->getChild('entities_list');\n+        if (!$entitiesMenuItem) {\n+            return;\n+        }\n+\n+        if ($this->cache->contains(static::CACHE_KEY)) {\n+            $children = $this->cache->fetch(static::CACHE_KEY);\n+        } else {\n+            $children = $this->getCustomEntitiesMenuConfig();\n+            $this->cache->save(static::CACHE_KEY, $children, static::CACHE_LIFETIME);\n+        }\n+\n+        foreach ($children as $child) {\n+            $entitiesMenuItem->addChild($child['label'], $child['options']);\n+        }\n+    }\n+\n+    /**\n+     * @return array\n+     */\n+    protected function getCustomEntitiesMenuConfig()\n+    {\n+        $children = [];\n+\n+        /** @var ConfigProvider $entityConfigProvider */\n+        /** @var ConfigProvider $entityExtendProvider */\n+        /** @var ConfigProvider $groupConfigProvider */\n+        $entityConfigProvider = $this->configManager->getProvider('entity');\n+        $entityExtendProvider = $this->configManager->getProvider('extend');\n+        $groupConfigProvider  = $this->configManager->getProvider('grouping');\n+\n+        $withHidden    = true; // TODO: move it to configuration\n+        $extendConfigs = $entityExtendProvider->getConfigs(null, $withHidden);\n+        $groupConfigs  = $groupConfigProvider->getConfigs(null, $withHidden);\n+\n+        foreach ($extendConfigs as $extendConfig) {\n+            $groupConfig = array_shift($groupConfigs);\n+\n+            if (!$this->isEntityMenuAvailable($extendConfig, $groupConfig)) {\n+                continue;\n             }\n \n-            sort($children);\n-            foreach ($children as $child) {\n-                $entitiesMenuItem->addChild($child['label'], $child['options']);\n+            $className    = $extendConfig->getId()->getClassname();\n+            $entityConfig = $entityConfigProvider->getConfig($className);\n+\n+            if (!class_exists($entityConfig->getId()->getClassName()) ||\n+                !$this->securityFacade->hasLoggedUser() ||\n+                !$this->securityFacade->isGranted('VIEW', 'entity:'.$className)\n+            ) {\n+                continue;\n             }\n+\n+            $label = $entityConfig->get('label') ?:\n+                sprintf(\n+                    'oro.custom_entity.%s.plural_label',\n+                    strtolower(ExtendHelper::getShortClassName($className))\n+                );\n+\n+            $children[$label] = [\n+                'label'   => $this->translator->trans($label),\n+                'options' => [\n+                    'route'           => 'oro_entity_index',\n+                    'routeParameters' => [\n+                        'entityName' => str_replace('\\\\', '_', $className)\n+                    ],\n+                    'extras'          => [\n+                        'safe_label' => true,\n+                        'routes'     => ['oro_entity_*']\n+                    ],\n+                ]\n+            ];\n         }\n \n+        sort($children);\n+\n+        return $children;\n     }\n \n     /**\n-     * @param Config $extendConfig\n+     * @param ConfigInterface $extendConfig\n+     * @param ConfigInterface $groupConfig\n      *\n      * @return bool\n      */\n-    protected function checkAvailability(Config $extendConfig)\n+    protected function isEntityMenuAvailable(ConfigInterface $extendConfig, ConfigInterface $groupConfig)\n     {\n         return\n-            $extendConfig->is('is_extend')\n-            && $extendConfig->get('owner') == ExtendScope::OWNER_CUSTOM\n+            // custom entity\n+            $extendConfig->get('owner') == ExtendScope::OWNER_CUSTOM\n+            // with active state\n             && $extendConfig->in(\n                 'state',\n                 [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_UPDATE]\n-            );\n+            )\n+            && (\n+                // is extend entity\n+                $extendConfig->is('is_extend')\n+                ||\n+                // or located in dictionary group OR is an enum\n+                (\n+                    in_array(GroupingScope::GROUP_DICTIONARY, $groupConfig->get('groups', false, []))\n+                    || false !== strpos($extendConfig->getId()->getClassName(), ExtendHelper::ENTITY_NAMESPACE . 'EV_')\n+                )\n+            )\n+            ;","path":"src/Oro/Bundle/EntityBundle/EventListener/NavigationListener.php","position":210,"original_position":210,"commit_id":"34c11128d92f41878583bc7b498ceb999e3d8ad4","original_commit_id":"34c11128d92f41878583bc7b498ceb999e3d8ad4","user":{"login":"alex-n-2k7","id":3510470,"avatar_url":"https://avatars.githubusercontent.com/u/3510470?v=3","gravatar_id":"","url":"https://api.github.com/users/alex-n-2k7","html_url":"https://github.com/alex-n-2k7","followers_url":"https://api.github.com/users/alex-n-2k7/followers","following_url":"https://api.github.com/users/alex-n-2k7/following{/other_user}","gists_url":"https://api.github.com/users/alex-n-2k7/gists{/gist_id}","starred_url":"https://api.github.com/users/alex-n-2k7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex-n-2k7/subscriptions","organizations_url":"https://api.github.com/users/alex-n-2k7/orgs","repos_url":"https://api.github.com/users/alex-n-2k7/repos","events_url":"https://api.github.com/users/alex-n-2k7/events{/privacy}","received_events_url":"https://api.github.com/users/alex-n-2k7/received_events","type":"User","site_admin":false},"body":"move to previous line","created_at":"2016-02-09T16:43:04Z","updated_at":"2016-02-09T16:43:04Z","html_url":"https://github.com/orocrm/platform/pull/338#discussion_r52335104","pull_request_url":"https://api.github.com/repos/orocrm/platform/pulls/338","_links":{"self":{"href":"https://api.github.com/repos/orocrm/platform/pulls/comments/52335104"},"html":{"href":"https://github.com/orocrm/platform/pull/338#discussion_r52335104"},"pull_request":{"href":"https://api.github.com/repos/orocrm/platform/pulls/338"}}},"pull_request":{"url":"https://api.github.com/repos/orocrm/platform/pulls/338","id":49842501,"html_url":"https://github.com/orocrm/platform/pull/338","diff_url":"https://github.com/orocrm/platform/pull/338.diff","patch_url":"https://github.com/orocrm/platform/pull/338.patch","issue_url":"https://api.github.com/repos/orocrm/platform/issues/338","number":338,"state":"open","locked":false,"title":"Feature: Dictionaries (custom entities) and enum CRUD","user":{"login":"ishakuta","id":193552,"avatar_url":"https://avatars.githubusercontent.com/u/193552?v=3","gravatar_id":"","url":"https://api.github.com/users/ishakuta","html_url":"https://github.com/ishakuta","followers_url":"https://api.github.com/users/ishakuta/followers","following_url":"https://api.github.com/users/ishakuta/following{/other_user}","gists_url":"https://api.github.com/users/ishakuta/gists{/gist_id}","starred_url":"https://api.github.com/users/ishakuta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ishakuta/subscriptions","organizations_url":"https://api.github.com/users/ishakuta/orgs","repos_url":"https://api.github.com/users/ishakuta/repos","events_url":"https://api.github.com/users/ishakuta/events{/privacy}","received_events_url":"https://api.github.com/users/ishakuta/received_events","type":"User","site_admin":false},"body":"It's possible to edit enums out of the box from entity management UI, but if it's not allowed for some user, this approach could be helpful:\r\n\r\n- allow to add/edit custom enums, dictionaries and custom entities that have non-integer primary key\r\n- automatically add menu items for these entities\r\n- add validation for all enum entities\r\n","created_at":"2015-11-05T16:00:26Z","updated_at":"2016-02-09T16:43:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8e6d4a8881ae22ce7a13e66bb93f7a7ff1753ceb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/orocrm/platform/pulls/338/commits","review_comments_url":"https://api.github.com/repos/orocrm/platform/pulls/338/comments","review_comment_url":"https://api.github.com/repos/orocrm/platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/orocrm/platform/issues/338/comments","statuses_url":"https://api.github.com/repos/orocrm/platform/statuses/34c11128d92f41878583bc7b498ceb999e3d8ad4","head":{"label":"trustify:feature/dict-enum-crud","ref":"feature/dict-enum-crud","sha":"34c11128d92f41878583bc7b498ceb999e3d8ad4","user":{"login":"trustify","id":11923723,"avatar_url":"https://avatars.githubusercontent.com/u/11923723?v=3","gravatar_id":"","url":"https://api.github.com/users/trustify","html_url":"https://github.com/trustify","followers_url":"https://api.github.com/users/trustify/followers","following_url":"https://api.github.com/users/trustify/following{/other_user}","gists_url":"https://api.github.com/users/trustify/gists{/gist_id}","starred_url":"https://api.github.com/users/trustify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trustify/subscriptions","organizations_url":"https://api.github.com/users/trustify/orgs","repos_url":"https://api.github.com/users/trustify/repos","events_url":"https://api.github.com/users/trustify/events{/privacy}","received_events_url":"https://api.github.com/users/trustify/received_events","type":"Organization","site_admin":false},"repo":{"id":39975403,"name":"oroplatform","full_name":"trustify/oroplatform","owner":{"login":"trustify","id":11923723,"avatar_url":"https://avatars.githubusercontent.com/u/11923723?v=3","gravatar_id":"","url":"https://api.github.com/users/trustify","html_url":"https://github.com/trustify","followers_url":"https://api.github.com/users/trustify/followers","following_url":"https://api.github.com/users/trustify/following{/other_user}","gists_url":"https://api.github.com/users/trustify/gists{/gist_id}","starred_url":"https://api.github.com/users/trustify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trustify/subscriptions","organizations_url":"https://api.github.com/users/trustify/orgs","repos_url":"https://api.github.com/users/trustify/repos","events_url":"https://api.github.com/users/trustify/events{/privacy}","received_events_url":"https://api.github.com/users/trustify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/trustify/oroplatform","description":"The Oro Platform - Business Application Platform (BAP)","fork":true,"url":"https://api.github.com/repos/trustify/oroplatform","forks_url":"https://api.github.com/repos/trustify/oroplatform/forks","keys_url":"https://api.github.com/repos/trustify/oroplatform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/trustify/oroplatform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/trustify/oroplatform/teams","hooks_url":"https://api.github.com/repos/trustify/oroplatform/hooks","issue_events_url":"https://api.github.com/repos/trustify/oroplatform/issues/events{/number}","events_url":"https://api.github.com/repos/trustify/oroplatform/events","assignees_url":"https://api.github.com/repos/trustify/oroplatform/assignees{/user}","branches_url":"https://api.github.com/repos/trustify/oroplatform/branches{/branch}","tags_url":"https://api.github.com/repos/trustify/oroplatform/tags","blobs_url":"https://api.github.com/repos/trustify/oroplatform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/trustify/oroplatform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/trustify/oroplatform/git/refs{/sha}","trees_url":"https://api.github.com/repos/trustify/oroplatform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/trustify/oroplatform/statuses/{sha}","languages_url":"https://api.github.com/repos/trustify/oroplatform/languages","stargazers_url":"https://api.github.com/repos/trustify/oroplatform/stargazers","contributors_url":"https://api.github.com/repos/trustify/oroplatform/contributors","subscribers_url":"https://api.github.com/repos/trustify/oroplatform/subscribers","subscription_url":"https://api.github.com/repos/trustify/oroplatform/subscription","commits_url":"https://api.github.com/repos/trustify/oroplatform/commits{/sha}","git_commits_url":"https://api.github.com/repos/trustify/oroplatform/git/commits{/sha}","comments_url":"https://api.github.com/repos/trustify/oroplatform/comments{/number}","issue_comment_url":"https://api.github.com/repos/trustify/oroplatform/issues/comments{/number}","contents_url":"https://api.github.com/repos/trustify/oroplatform/contents/{+path}","compare_url":"https://api.github.com/repos/trustify/oroplatform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/trustify/oroplatform/merges","archive_url":"https://api.github.com/repos/trustify/oroplatform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/trustify/oroplatform/downloads","issues_url":"https://api.github.com/repos/trustify/oroplatform/issues{/number}","pulls_url":"https://api.github.com/repos/trustify/oroplatform/pulls{/number}","milestones_url":"https://api.github.com/repos/trustify/oroplatform/milestones{/number}","notifications_url":"https://api.github.com/repos/trustify/oroplatform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/trustify/oroplatform/labels{/name}","releases_url":"https://api.github.com/repos/trustify/oroplatform/releases{/id}","deployments_url":"https://api.github.com/repos/trustify/oroplatform/deployments","created_at":"2015-07-30T22:37:13Z","updated_at":"2016-01-27T15:06:58Z","pushed_at":"2016-02-04T15:17:19Z","git_url":"git://github.com/trustify/oroplatform.git","ssh_url":"git@github.com:trustify/oroplatform.git","clone_url":"https://github.com/trustify/oroplatform.git","svn_url":"https://github.com/trustify/oroplatform","homepage":"","size":84345,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"orocrm:master","ref":"master","sha":"8d2a9dd32d7f0f2fff969a3554bd3669fbcac53a","user":{"login":"orocrm","id":4165718,"avatar_url":"https://avatars.githubusercontent.com/u/4165718?v=3","gravatar_id":"","url":"https://api.github.com/users/orocrm","html_url":"https://github.com/orocrm","followers_url":"https://api.github.com/users/orocrm/followers","following_url":"https://api.github.com/users/orocrm/following{/other_user}","gists_url":"https://api.github.com/users/orocrm/gists{/gist_id}","starred_url":"https://api.github.com/users/orocrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orocrm/subscriptions","organizations_url":"https://api.github.com/users/orocrm/orgs","repos_url":"https://api.github.com/users/orocrm/repos","events_url":"https://api.github.com/users/orocrm/events{/privacy}","received_events_url":"https://api.github.com/users/orocrm/received_events","type":"Organization","site_admin":false},"repo":{"id":10450961,"name":"platform","full_name":"orocrm/platform","owner":{"login":"orocrm","id":4165718,"avatar_url":"https://avatars.githubusercontent.com/u/4165718?v=3","gravatar_id":"","url":"https://api.github.com/users/orocrm","html_url":"https://github.com/orocrm","followers_url":"https://api.github.com/users/orocrm/followers","following_url":"https://api.github.com/users/orocrm/following{/other_user}","gists_url":"https://api.github.com/users/orocrm/gists{/gist_id}","starred_url":"https://api.github.com/users/orocrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orocrm/subscriptions","organizations_url":"https://api.github.com/users/orocrm/orgs","repos_url":"https://api.github.com/users/orocrm/repos","events_url":"https://api.github.com/users/orocrm/events{/privacy}","received_events_url":"https://api.github.com/users/orocrm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orocrm/platform","description":"The OroPlatform - Business Application Platform (BAP)","fork":false,"url":"https://api.github.com/repos/orocrm/platform","forks_url":"https://api.github.com/repos/orocrm/platform/forks","keys_url":"https://api.github.com/repos/orocrm/platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orocrm/platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orocrm/platform/teams","hooks_url":"https://api.github.com/repos/orocrm/platform/hooks","issue_events_url":"https://api.github.com/repos/orocrm/platform/issues/events{/number}","events_url":"https://api.github.com/repos/orocrm/platform/events","assignees_url":"https://api.github.com/repos/orocrm/platform/assignees{/user}","branches_url":"https://api.github.com/repos/orocrm/platform/branches{/branch}","tags_url":"https://api.github.com/repos/orocrm/platform/tags","blobs_url":"https://api.github.com/repos/orocrm/platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orocrm/platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orocrm/platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/orocrm/platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orocrm/platform/statuses/{sha}","languages_url":"https://api.github.com/repos/orocrm/platform/languages","stargazers_url":"https://api.github.com/repos/orocrm/platform/stargazers","contributors_url":"https://api.github.com/repos/orocrm/platform/contributors","subscribers_url":"https://api.github.com/repos/orocrm/platform/subscribers","subscription_url":"https://api.github.com/repos/orocrm/platform/subscription","commits_url":"https://api.github.com/repos/orocrm/platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/orocrm/platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/orocrm/platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/orocrm/platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/orocrm/platform/contents/{+path}","compare_url":"https://api.github.com/repos/orocrm/platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orocrm/platform/merges","archive_url":"https://api.github.com/repos/orocrm/platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orocrm/platform/downloads","issues_url":"https://api.github.com/repos/orocrm/platform/issues{/number}","pulls_url":"https://api.github.com/repos/orocrm/platform/pulls{/number}","milestones_url":"https://api.github.com/repos/orocrm/platform/milestones{/number}","notifications_url":"https://api.github.com/repos/orocrm/platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orocrm/platform/labels{/name}","releases_url":"https://api.github.com/repos/orocrm/platform/releases{/id}","deployments_url":"https://api.github.com/repos/orocrm/platform/deployments","created_at":"2013-06-03T09:06:52Z","updated_at":"2016-02-09T14:52:40Z","pushed_at":"2016-02-09T06:52:01Z","git_url":"git://github.com/orocrm/platform.git","ssh_url":"git@github.com:orocrm/platform.git","clone_url":"https://github.com/orocrm/platform.git","svn_url":"https://github.com/orocrm/platform","homepage":"","size":85183,"stargazers_count":359,"watchers_count":359,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":170,"mirror_url":null,"open_issues_count":119,"forks":170,"open_issues":119,"watchers":359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/orocrm/platform/pulls/338"},"html":{"href":"https://github.com/orocrm/platform/pull/338"},"issue":{"href":"https://api.github.com/repos/orocrm/platform/issues/338"},"comments":{"href":"https://api.github.com/repos/orocrm/platform/issues/338/comments"},"review_comments":{"href":"https://api.github.com/repos/orocrm/platform/pulls/338/comments"},"review_comment":{"href":"https://api.github.com/repos/orocrm/platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/orocrm/platform/pulls/338/commits"},"statuses":{"href":"https://api.github.com/repos/orocrm/platform/statuses/34c11128d92f41878583bc7b498ceb999e3d8ad4"}}}}