{"action":"created","comment":{"url":"https://api.github.com/repos/amitaibu/og/pulls/comments/41763532","id":41763532,"diff_hunk":"@@ -17,6 +17,137 @@\n class Og {\n \n   /**\n+   * Static cache for groups per entity.\n+   *\n+   * @var array\n+   */\n+  protected static $entityGroupCache = [];\n+\n+  /**\n+   * Create an organic groups field in a bundle.\n+   *\n+   * @param $field_name\n+   *   The field name.\n+   * @param $entity_type\n+   *   The entity type.\n+   * @param $bundle\n+   *   The bundle name.\n+   */\n+  public static function createField($field_name, $entity_type, $bundle) {\n+    $og_field = static::fieldInfo($field_name)\n+      ->setEntityType($entity_type)\n+      ->setBundle($bundle);\n+\n+    if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {\n+      $og_field->fieldDefinition()->save();\n+    }\n+\n+    // Allow overriding the field name.\n+    // todo: ask if we need this.\n+//    $og_field['field']['field_name'] = $field_name;\n+//    if (empty($field)) {\n+//      $og_field['field']->save();\n+//    }\n+\n+    if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {\n+      $og_field->instanceDefinition()->save();\n+      // Clear the entity property info cache, as OG fields might add different\n+      // entity property info.\n+      static::invalidateCache();\n+    }\n+\n+    // Add the field to the form display manager.\n+    $displayForm = EntityFormDisplay::load($entity_type . '.' . $bundle . '.default');\n+    if (!$displayForm->getComponent($field_name) && $widgetDefinition = $og_field->widgetDefinition()) {\n+      $displayForm->setComponent($field_name, $widgetDefinition);\n+      $displayForm->save();\n+    }\n+\n+    // Define the view mode for the field.\n+    if ($fieldViewModes = $og_field->viewModesDefinition()) {\n+      $prefix = $entity_type . '.' . $bundle . '.';\n+      $viewModes = \\Drupal::entityManager()->getStorage('entity_view_display')->loadMultiple(array_keys($fieldViewModes));\n+\n+      foreach ($viewModes as $key => $viewMode) {\n+        $viewMode->setComponent($field_name, $fieldViewModes[$prefix . $key])->save();\n+      }\n+    }\n+  }\n+\n+  /**\n+   * Gets the groups an entity is associated with.\n+   *\n+   * @param $entity_type\n+   *   The entity type. Defaults to 'user'\n+   * @param $entity_id\n+   *   (optional) The entity ID.\n+   * @param $states\n+   *   (optional) Array with the state to return. Defaults to active.\n+   * @param $field_name\n+   *   (optional) The field name associated with the group.\n+   *\n+   * @return array\n+   *  An array with the group's entity type as the key, and array - keyed by\n+   *  the OG membership ID and the group ID as the value. If nothing found,\n+   *  then an empty array.\n+   */\n+  public static function getEntityGroups($entity_type = 'user', $entity_id = NULL, $states = [OG_STATE_ACTIVE], $field_name = NULL) {\n+    if ($entity_type == 'user' && empty($entity_id)) {","path":"src/Og.php","position":92,"original_position":92,"commit_id":"46d24d3de3ae367602f70e1e9416e34f7c801a3f","original_commit_id":"46d24d3de3ae367602f70e1e9416e34f7c801a3f","user":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"body":"Yes, exactly. I think removing this and making the parameters required is a much better way to go.","created_at":"2015-10-12T14:46:01Z","updated_at":"2015-10-12T14:46:01Z","html_url":"https://github.com/amitaibu/og/pull/13#discussion_r41763532","pull_request_url":"https://api.github.com/repos/amitaibu/og/pulls/13","_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments/41763532"},"html":{"href":"https://github.com/amitaibu/og/pull/13#discussion_r41763532"},"pull_request":{"href":"https://api.github.com/repos/amitaibu/og/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/amitaibu/og/pulls/13","id":47420956,"html_url":"https://github.com/amitaibu/og/pull/13","diff_url":"https://github.com/amitaibu/og/pull/13.diff","patch_url":"https://github.com/amitaibu/og/pull/13.patch","issue_url":"https://api.github.com/repos/amitaibu/og/issues/13","number":13,"state":"open","locked":false,"title":"Remove OG 'controller' class","user":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"body":"Lets ~~kill~~ remove the OG controller class. This can live in the Og class for now. I think we might want to talk about how we split this up further though, the Og class will become crowded pretty fast.","created_at":"2015-10-12T13:43:31Z","updated_at":"2015-10-12T14:46:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4053f0854f2d41e13d3ccb7d6e6d4cce965f5a51","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amitaibu/og/pulls/13/commits","review_comments_url":"https://api.github.com/repos/amitaibu/og/pulls/13/comments","review_comment_url":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amitaibu/og/issues/13/comments","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/46d24d3de3ae367602f70e1e9416e34f7c801a3f","head":{"label":"damiankloip:remove-OG-controller","ref":"remove-OG-controller","sha":"46d24d3de3ae367602f70e1e9416e34f7c801a3f","user":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"repo":{"id":40903339,"name":"og","full_name":"damiankloip/og","owner":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/damiankloip/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/damiankloip/og","forks_url":"https://api.github.com/repos/damiankloip/og/forks","keys_url":"https://api.github.com/repos/damiankloip/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/damiankloip/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/damiankloip/og/teams","hooks_url":"https://api.github.com/repos/damiankloip/og/hooks","issue_events_url":"https://api.github.com/repos/damiankloip/og/issues/events{/number}","events_url":"https://api.github.com/repos/damiankloip/og/events","assignees_url":"https://api.github.com/repos/damiankloip/og/assignees{/user}","branches_url":"https://api.github.com/repos/damiankloip/og/branches{/branch}","tags_url":"https://api.github.com/repos/damiankloip/og/tags","blobs_url":"https://api.github.com/repos/damiankloip/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/damiankloip/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/damiankloip/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/damiankloip/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/damiankloip/og/statuses/{sha}","languages_url":"https://api.github.com/repos/damiankloip/og/languages","stargazers_url":"https://api.github.com/repos/damiankloip/og/stargazers","contributors_url":"https://api.github.com/repos/damiankloip/og/contributors","subscribers_url":"https://api.github.com/repos/damiankloip/og/subscribers","subscription_url":"https://api.github.com/repos/damiankloip/og/subscription","commits_url":"https://api.github.com/repos/damiankloip/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/damiankloip/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/damiankloip/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/damiankloip/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/damiankloip/og/contents/{+path}","compare_url":"https://api.github.com/repos/damiankloip/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/damiankloip/og/merges","archive_url":"https://api.github.com/repos/damiankloip/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/damiankloip/og/downloads","issues_url":"https://api.github.com/repos/damiankloip/og/issues{/number}","pulls_url":"https://api.github.com/repos/damiankloip/og/pulls{/number}","milestones_url":"https://api.github.com/repos/damiankloip/og/milestones{/number}","notifications_url":"https://api.github.com/repos/damiankloip/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/damiankloip/og/labels{/name}","releases_url":"https://api.github.com/repos/damiankloip/og/releases{/id}","created_at":"2015-08-17T14:54:27Z","updated_at":"2015-08-17T14:54:28Z","pushed_at":"2015-10-12T14:00:22Z","git_url":"git://github.com/damiankloip/og.git","ssh_url":"git@github.com:damiankloip/og.git","clone_url":"https://github.com/damiankloip/og.git","svn_url":"https://github.com/damiankloip/og","homepage":"","size":5104,"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":"7.x-2.x"}},"base":{"label":"amitaibu:8.x-1.x","ref":"8.x-1.x","sha":"db5df79add8fc399b599d1d5cd71f4a8e5c3ca83","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"repo":{"id":42034806,"name":"og","full_name":"amitaibu/og","owner":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amitaibu/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/amitaibu/og","forks_url":"https://api.github.com/repos/amitaibu/og/forks","keys_url":"https://api.github.com/repos/amitaibu/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amitaibu/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amitaibu/og/teams","hooks_url":"https://api.github.com/repos/amitaibu/og/hooks","issue_events_url":"https://api.github.com/repos/amitaibu/og/issues/events{/number}","events_url":"https://api.github.com/repos/amitaibu/og/events","assignees_url":"https://api.github.com/repos/amitaibu/og/assignees{/user}","branches_url":"https://api.github.com/repos/amitaibu/og/branches{/branch}","tags_url":"https://api.github.com/repos/amitaibu/og/tags","blobs_url":"https://api.github.com/repos/amitaibu/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amitaibu/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amitaibu/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/amitaibu/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/{sha}","languages_url":"https://api.github.com/repos/amitaibu/og/languages","stargazers_url":"https://api.github.com/repos/amitaibu/og/stargazers","contributors_url":"https://api.github.com/repos/amitaibu/og/contributors","subscribers_url":"https://api.github.com/repos/amitaibu/og/subscribers","subscription_url":"https://api.github.com/repos/amitaibu/og/subscription","commits_url":"https://api.github.com/repos/amitaibu/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/amitaibu/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/amitaibu/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/amitaibu/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/amitaibu/og/contents/{+path}","compare_url":"https://api.github.com/repos/amitaibu/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amitaibu/og/merges","archive_url":"https://api.github.com/repos/amitaibu/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amitaibu/og/downloads","issues_url":"https://api.github.com/repos/amitaibu/og/issues{/number}","pulls_url":"https://api.github.com/repos/amitaibu/og/pulls{/number}","milestones_url":"https://api.github.com/repos/amitaibu/og/milestones{/number}","notifications_url":"https://api.github.com/repos/amitaibu/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amitaibu/og/labels{/name}","releases_url":"https://api.github.com/repos/amitaibu/og/releases{/id}","created_at":"2015-09-07T06:16:12Z","updated_at":"2015-10-08T12:55:50Z","pushed_at":"2015-10-12T14:01:06Z","git_url":"git://github.com/amitaibu/og.git","ssh_url":"git@github.com:amitaibu/og.git","clone_url":"https://github.com/amitaibu/og.git","svn_url":"https://github.com/amitaibu/og","homepage":"","size":5528,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"8.x-1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/13"},"html":{"href":"https://github.com/amitaibu/og/pull/13"},"issue":{"href":"https://api.github.com/repos/amitaibu/og/issues/13"},"comments":{"href":"https://api.github.com/repos/amitaibu/og/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/amitaibu/og/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amitaibu/og/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/amitaibu/og/statuses/46d24d3de3ae367602f70e1e9416e34f7c801a3f"}}}}