{"action":"created","comment":{"url":"https://api.github.com/repos/fago/entity/pulls/comments/46081427","id":46081427,"diff_hunk":"@@ -0,0 +1,126 @@\n+<?php\n+\n+/**\n+ * @file\n+ * Contains \\Drupal\\entity\\Controller\\EntityCreateController.\n+ */\n+\n+namespace Drupal\\entity\\Controller;\n+\n+use Drupal\\Core\\Controller\\ControllerBase;\n+use Drupal\\Core\\Url;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+\n+/**\n+ * A generic controller for creating entities.\n+ */\n+class EntityCreateController extends ControllerBase {\n+\n+  /**\n+   * Displays add links for the available bundles.\n+   *\n+   * Redirects to the add form if there's only one bundle available.\n+   *\n+   * @param string $entity_type_id\n+   *   The entity type ID.\n+   * @param \\Symfony\\Component\\HttpFoundation\\Request $request\n+   *   The request.\n+   *\n+   * @return \\Symfony\\Component\\HttpFoundation\\RedirectResponse|array\n+   *   If there's only one available bundle, a redirect response.\n+   *   Otherwise, a render array with the add links for each bundle.\n+   */\n+  public function addPage($entity_type_id, Request $request) {\n+    $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id);\n+    $bundle_type = $entity_type->getBundleEntityType();\n+    $form_route_name = 'entity.' . $bundle_type . '.add_form';\n+    $bundles = $this->entityTypeManager()->getStorage($bundle_type)->loadMultiple();\n+    // Filter out the bundles the user doesn't have access to.\n+    $access_control_handler = $this->entityTypeManager()->getAccessControlHandler($bundle_type);\n+    $bundles = array_filter($bundles, function($bundle) use ($access_control_handler) {\n+      return $access_control_handler->createAccess($bundle->id());\n+    });\n+    // Redirect if there's only one bundle available.\n+    if (count($bundles) == 1) {\n+      $bundle = reset($bundles);\n+\n+      return $this->redirect($form_route_name, [$bundle_type => $bundle->id()]);\n+    }\n+\n+    return [\n+      '#theme' => 'entity_add_list',\n+      '#bundles' => $bundles,\n+      '#bundle_type' => $bundle_type,\n+      '#form_route_name' => $form_route_name,\n+    ];\n+  }\n+\n+  /**\n+   * Gets the title for the \"Entity Add\" page.\n+   *\n+   * @param string $entity_type_id\n+   *   The entity type ID.\n+   *\n+   * @return string\n+   *   The title customized for this entity type.\n+   */\n+  public function addPageTitle($entity_type_id) {\n+    $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id);\n+    $bundle_type = $entity_type->getBundleEntityType();\n+    $bundles = $this->entityTypeManager()->getStorage($bundle_type)->loadMultiple();\n+    $bundle  = $bundles && count($bundles) == 1 ? reset($bundles)  : FALSE;\n+\n+    $args = [\n+      '@entity-label' => $entity_type->getLabel(),\n+      '%type' => $bundle ? $bundle->label() : '',","path":"src/Controller/EntityCreateController.php","position":75,"original_position":75,"commit_id":"c8b392772b06204ab2164480faecee88a00bafe5","original_commit_id":"c8b392772b06204ab2164480faecee88a00bafe5","user":{"login":"dawehner","id":29678,"avatar_url":"https://avatars.githubusercontent.com/u/29678?v=3","gravatar_id":"","url":"https://api.github.com/users/dawehner","html_url":"https://github.com/dawehner","followers_url":"https://api.github.com/users/dawehner/followers","following_url":"https://api.github.com/users/dawehner/following{/other_user}","gists_url":"https://api.github.com/users/dawehner/gists{/gist_id}","starred_url":"https://api.github.com/users/dawehner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dawehner/subscriptions","organizations_url":"https://api.github.com/users/dawehner/orgs","repos_url":"https://api.github.com/users/dawehner/repos","events_url":"https://api.github.com/users/dawehner/events{/privacy}","received_events_url":"https://api.github.com/users/dawehner/received_events","type":"User","site_admin":false},"body":"what about using %bundle instead as placeholder?","created_at":"2015-11-28T16:18:42Z","updated_at":"2015-11-28T16:18:42Z","html_url":"https://github.com/fago/entity/pull/11#discussion_r46081427","pull_request_url":"https://api.github.com/repos/fago/entity/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/fago/entity/pulls/comments/46081427"},"html":{"href":"https://github.com/fago/entity/pull/11#discussion_r46081427"},"pull_request":{"href":"https://api.github.com/repos/fago/entity/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/fago/entity/pulls/11","id":52043310,"html_url":"https://github.com/fago/entity/pull/11","diff_url":"https://github.com/fago/entity/pull/11.diff","patch_url":"https://github.com/fago/entity/pull/11.patch","issue_url":"https://api.github.com/repos/fago/entity/issues/11","number":11,"state":"open","locked":false,"title":"[WIP] Add a route provider and controller for add page/form.","user":{"login":"bojanz","id":330162,"avatar_url":"https://avatars.githubusercontent.com/u/330162?v=3","gravatar_id":"","url":"https://api.github.com/users/bojanz","html_url":"https://github.com/bojanz","followers_url":"https://api.github.com/users/bojanz/followers","following_url":"https://api.github.com/users/bojanz/following{/other_user}","gists_url":"https://api.github.com/users/bojanz/gists{/gist_id}","starred_url":"https://api.github.com/users/bojanz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bojanz/subscriptions","organizations_url":"https://api.github.com/users/bojanz/orgs","repos_url":"https://api.github.com/users/bojanz/repos","events_url":"https://api.github.com/users/bojanz/events{/privacy}","received_events_url":"https://api.github.com/users/bojanz/received_events","type":"User","site_admin":false},"body":"Continues the work from #7:\r\n\r\n- Deleted the collections route generation.\r\n- Added a custom theme for the add list.\r\n- Added the missing redirect&access checks to the addPage method.\r\n- Code cleanups.\r\n\r\nStill untested.","created_at":"2015-11-28T16:14:36Z","updated_at":"2015-11-28T16:18:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f627169edfaba3fce4cca1050ae7c5121e545396","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fago/entity/pulls/11/commits","review_comments_url":"https://api.github.com/repos/fago/entity/pulls/11/comments","review_comment_url":"https://api.github.com/repos/fago/entity/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fago/entity/issues/11/comments","statuses_url":"https://api.github.com/repos/fago/entity/statuses/c8b392772b06204ab2164480faecee88a00bafe5","head":{"label":"bojanz:add-list","ref":"add-list","sha":"c8b392772b06204ab2164480faecee88a00bafe5","user":{"login":"bojanz","id":330162,"avatar_url":"https://avatars.githubusercontent.com/u/330162?v=3","gravatar_id":"","url":"https://api.github.com/users/bojanz","html_url":"https://github.com/bojanz","followers_url":"https://api.github.com/users/bojanz/followers","following_url":"https://api.github.com/users/bojanz/following{/other_user}","gists_url":"https://api.github.com/users/bojanz/gists{/gist_id}","starred_url":"https://api.github.com/users/bojanz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bojanz/subscriptions","organizations_url":"https://api.github.com/users/bojanz/orgs","repos_url":"https://api.github.com/users/bojanz/repos","events_url":"https://api.github.com/users/bojanz/events{/privacy}","received_events_url":"https://api.github.com/users/bojanz/received_events","type":"User","site_admin":false},"repo":{"id":44984096,"name":"entity","full_name":"bojanz/entity","owner":{"login":"bojanz","id":330162,"avatar_url":"https://avatars.githubusercontent.com/u/330162?v=3","gravatar_id":"","url":"https://api.github.com/users/bojanz","html_url":"https://github.com/bojanz","followers_url":"https://api.github.com/users/bojanz/followers","following_url":"https://api.github.com/users/bojanz/following{/other_user}","gists_url":"https://api.github.com/users/bojanz/gists{/gist_id}","starred_url":"https://api.github.com/users/bojanz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bojanz/subscriptions","organizations_url":"https://api.github.com/users/bojanz/orgs","repos_url":"https://api.github.com/users/bojanz/repos","events_url":"https://api.github.com/users/bojanz/events{/privacy}","received_events_url":"https://api.github.com/users/bojanz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bojanz/entity","description":"http://drupal.org/project/entity development for Drupal 8.","fork":true,"url":"https://api.github.com/repos/bojanz/entity","forks_url":"https://api.github.com/repos/bojanz/entity/forks","keys_url":"https://api.github.com/repos/bojanz/entity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bojanz/entity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bojanz/entity/teams","hooks_url":"https://api.github.com/repos/bojanz/entity/hooks","issue_events_url":"https://api.github.com/repos/bojanz/entity/issues/events{/number}","events_url":"https://api.github.com/repos/bojanz/entity/events","assignees_url":"https://api.github.com/repos/bojanz/entity/assignees{/user}","branches_url":"https://api.github.com/repos/bojanz/entity/branches{/branch}","tags_url":"https://api.github.com/repos/bojanz/entity/tags","blobs_url":"https://api.github.com/repos/bojanz/entity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bojanz/entity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bojanz/entity/git/refs{/sha}","trees_url":"https://api.github.com/repos/bojanz/entity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bojanz/entity/statuses/{sha}","languages_url":"https://api.github.com/repos/bojanz/entity/languages","stargazers_url":"https://api.github.com/repos/bojanz/entity/stargazers","contributors_url":"https://api.github.com/repos/bojanz/entity/contributors","subscribers_url":"https://api.github.com/repos/bojanz/entity/subscribers","subscription_url":"https://api.github.com/repos/bojanz/entity/subscription","commits_url":"https://api.github.com/repos/bojanz/entity/commits{/sha}","git_commits_url":"https://api.github.com/repos/bojanz/entity/git/commits{/sha}","comments_url":"https://api.github.com/repos/bojanz/entity/comments{/number}","issue_comment_url":"https://api.github.com/repos/bojanz/entity/issues/comments{/number}","contents_url":"https://api.github.com/repos/bojanz/entity/contents/{+path}","compare_url":"https://api.github.com/repos/bojanz/entity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bojanz/entity/merges","archive_url":"https://api.github.com/repos/bojanz/entity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bojanz/entity/downloads","issues_url":"https://api.github.com/repos/bojanz/entity/issues{/number}","pulls_url":"https://api.github.com/repos/bojanz/entity/pulls{/number}","milestones_url":"https://api.github.com/repos/bojanz/entity/milestones{/number}","notifications_url":"https://api.github.com/repos/bojanz/entity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bojanz/entity/labels{/name}","releases_url":"https://api.github.com/repos/bojanz/entity/releases{/id}","created_at":"2015-10-26T17:04:21Z","updated_at":"2015-11-28T16:11:55Z","pushed_at":"2015-11-28T16:13:19Z","git_url":"git://github.com/bojanz/entity.git","ssh_url":"git@github.com:bojanz/entity.git","clone_url":"https://github.com/bojanz/entity.git","svn_url":"https://github.com/bojanz/entity","homepage":null,"size":15,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"8.x-1.x"}},"base":{"label":"fago:8.x-1.x","ref":"8.x-1.x","sha":"9bfeb288ca13ca00b7d8b4b4d292635a1133cd7a","user":{"login":"fago","id":132232,"avatar_url":"https://avatars.githubusercontent.com/u/132232?v=3","gravatar_id":"","url":"https://api.github.com/users/fago","html_url":"https://github.com/fago","followers_url":"https://api.github.com/users/fago/followers","following_url":"https://api.github.com/users/fago/following{/other_user}","gists_url":"https://api.github.com/users/fago/gists{/gist_id}","starred_url":"https://api.github.com/users/fago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fago/subscriptions","organizations_url":"https://api.github.com/users/fago/orgs","repos_url":"https://api.github.com/users/fago/repos","events_url":"https://api.github.com/users/fago/events{/privacy}","received_events_url":"https://api.github.com/users/fago/received_events","type":"User","site_admin":false},"repo":{"id":44748674,"name":"entity","full_name":"fago/entity","owner":{"login":"fago","id":132232,"avatar_url":"https://avatars.githubusercontent.com/u/132232?v=3","gravatar_id":"","url":"https://api.github.com/users/fago","html_url":"https://github.com/fago","followers_url":"https://api.github.com/users/fago/followers","following_url":"https://api.github.com/users/fago/following{/other_user}","gists_url":"https://api.github.com/users/fago/gists{/gist_id}","starred_url":"https://api.github.com/users/fago/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fago/subscriptions","organizations_url":"https://api.github.com/users/fago/orgs","repos_url":"https://api.github.com/users/fago/repos","events_url":"https://api.github.com/users/fago/events{/privacy}","received_events_url":"https://api.github.com/users/fago/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fago/entity","description":"http://drupal.org/project/entity development for Drupal 8.","fork":false,"url":"https://api.github.com/repos/fago/entity","forks_url":"https://api.github.com/repos/fago/entity/forks","keys_url":"https://api.github.com/repos/fago/entity/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fago/entity/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fago/entity/teams","hooks_url":"https://api.github.com/repos/fago/entity/hooks","issue_events_url":"https://api.github.com/repos/fago/entity/issues/events{/number}","events_url":"https://api.github.com/repos/fago/entity/events","assignees_url":"https://api.github.com/repos/fago/entity/assignees{/user}","branches_url":"https://api.github.com/repos/fago/entity/branches{/branch}","tags_url":"https://api.github.com/repos/fago/entity/tags","blobs_url":"https://api.github.com/repos/fago/entity/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fago/entity/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fago/entity/git/refs{/sha}","trees_url":"https://api.github.com/repos/fago/entity/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fago/entity/statuses/{sha}","languages_url":"https://api.github.com/repos/fago/entity/languages","stargazers_url":"https://api.github.com/repos/fago/entity/stargazers","contributors_url":"https://api.github.com/repos/fago/entity/contributors","subscribers_url":"https://api.github.com/repos/fago/entity/subscribers","subscription_url":"https://api.github.com/repos/fago/entity/subscription","commits_url":"https://api.github.com/repos/fago/entity/commits{/sha}","git_commits_url":"https://api.github.com/repos/fago/entity/git/commits{/sha}","comments_url":"https://api.github.com/repos/fago/entity/comments{/number}","issue_comment_url":"https://api.github.com/repos/fago/entity/issues/comments{/number}","contents_url":"https://api.github.com/repos/fago/entity/contents/{+path}","compare_url":"https://api.github.com/repos/fago/entity/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fago/entity/merges","archive_url":"https://api.github.com/repos/fago/entity/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fago/entity/downloads","issues_url":"https://api.github.com/repos/fago/entity/issues{/number}","pulls_url":"https://api.github.com/repos/fago/entity/pulls{/number}","milestones_url":"https://api.github.com/repos/fago/entity/milestones{/number}","notifications_url":"https://api.github.com/repos/fago/entity/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fago/entity/labels{/name}","releases_url":"https://api.github.com/repos/fago/entity/releases{/id}","created_at":"2015-10-22T13:56:53Z","updated_at":"2015-11-28T14:14:57Z","pushed_at":"2015-11-28T16:18:00Z","git_url":"git://github.com/fago/entity.git","ssh_url":"git@github.com:fago/entity.git","clone_url":"https://github.com/fago/entity.git","svn_url":"https://github.com/fago/entity","homepage":null,"size":39,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":0,"default_branch":"8.x-1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/fago/entity/pulls/11"},"html":{"href":"https://github.com/fago/entity/pull/11"},"issue":{"href":"https://api.github.com/repos/fago/entity/issues/11"},"comments":{"href":"https://api.github.com/repos/fago/entity/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/fago/entity/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/fago/entity/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fago/entity/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/fago/entity/statuses/c8b392772b06204ab2164480faecee88a00bafe5"}}}}