Using jsonpi jsonapi/group_content/business-group_node-article to make a post

Header:
Authorization:Basic YWRtaW46U3BhcmsxMjMh
Content-Type:application/vnd.api+json
Accept:application/vnd.api+json

Result:

TypeError: Argument 1 passed to Drupal\group\Plugin\GroupContentEnablerBase::createAccess() must implement interface Drupal\group\Entity\GroupInterface, null given, called in /app/www/groupjson4/modules/contrib/group/src/Entity/Access/GroupContentAccessControlHandler.php on line 30 in Drupal\group\Plugin\GroupContentEnablerBase->createAccess() (line 321 of /app/www/groupjson4/modules/contrib/group/src/Plugin/GroupContentEnablerBase.php) #0 /app/www/groupjson4/modules/contrib/group/src/Entity/Access/GroupContentAccessControlHandler.php(30): Drupal\group\Plugin\GroupContentEnablerBase->createAccess(NULL, Object(Drupal\Core\Session\AccountProxy)) #1 /app/www/groupjson4/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php(260): Drupal\group\Entity\Access\GroupContentAccessControlHandler->checkCreateAccess(Object(Drupal\Core\Session\AccountProxy), Array, 'business-group_...') #2 /app/www/groupjson4/core/lib/Drupal/Core/Entity/ContentEntityBase.php(627): Drupal\Core\Entity\EntityAccessControlHandler->createAccess('business-group_...', Object(Drupal\Core\Session\AccountProxy), Array, true) #3 /app/www/groupjson4/modules/contrib/jsonapi/src/Controller/EntityResource.php(194): Drupal\Core\Entity\ContentEntityBase->access('create', NULL, true) #4 [internal function]: Drupal\jsonapi\Controller\EntityResource->createIndividual(Object(Drupal\group\Entity\GroupContent), Object(Symfony\Component\HttpFoundation\Request)) #5 /app/www/groupjson4/modules/contrib/jsonapi/src/Controller/RequestHandler.php(89): call_user_func_array(Array, Array) #6 /app/www/groupjson4/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\jsonapi\Controller\RequestHandler->Drupal\jsonapi\Controller\{closure}() #7 /app/www/groupjson4/modules/contrib/jsonapi/src/Controller/RequestHandler.php(90): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #8 [internal function]: Drupal\jsonapi\Controller\RequestHandler->handle(Object(Drupal\Core\Routing\RouteMatch), Object(Symfony\Component\HttpFoundation\Request)) #9 /app/www/groupjson4/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #10 /app/www/groupjson4/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #11 /app/www/groupjson4/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #12 /app/www/groupjson4/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #13 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #14 /app/www/groupjson4/vendor/symfony/http-kernel/HttpKernel.php(153): call_user_func_array(Object(Closure), Array) #15 /app/www/groupjson4/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #16 /app/www/groupjson4/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /app/www/groupjson4/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /app/www/groupjson4/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /app/www/groupjson4/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /app/www/groupjson4/modules/contrib/jsonapi/src/StackMiddleware/FormatSetter.php(40): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /app/www/groupjson4/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /app/www/groupjson4/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /app/www/groupjson4/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /app/www/groupjson4/core/lib/Drupal/Core/DrupalKernel.php(657): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /app/www/groupjson4/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #26 {main}.

Comments

caseylau created an issue. See original summary.

lawxen’s picture

Title: Use jaonpi to post group content article get error » Use jsonapi to post group content article get error
lawxen’s picture

Wim Leers’s picture

Title: Use jsonapi to post group content article get error » Using JSON:API to POST group content article results in error due to `$context['group']` being required
Issue tags: +API-First Initiative
Wim Leers’s picture

tanasi [10:23 AM]
I am getting a TypeError:
`Argument 1 passed to Drupal\group\Plugin\GroupContentEnablerBase::createAccess() must implement interface Drupal\group\Entity\GroupInterface, null given, called in /var/www/web/modules/contrib/group/src/Entity/Access/GroupContentAccessControlHandler.php on line 30 in Drupal\group\Plugin\GroupContentEnablerBase->createAccess().`
I am trying to POST using JSON:API a node on GROUP (drupal.org/project/group). Does this mean that it hasn't been implemented or am I doing something wrong? (edited) 

e0ipso [10:58 AM]
@tanasi I'd recommend doing a GET for an existing Group and posting that JSON with modified values

tanasi [11:08 AM]
@e0ipso yes, this is what I have done. I have included in relationships: `group_content_type`, `gid`, `entity_id`, `uid`.  I just ommitted only the `links` which don't seem to be mandatory.

e0ipso [11:09 AM]
@tanasi make sure to skip `id` and `drupal_internal__*` when POSTing

wimleers (he/him) [11:11 AM]
@tanasi So that’s happening in `\Drupal\group\Plugin\GroupContentEnablerInterface::createAccess`, when `\Drupal\group\Entity\Access\GroupContentAccessControlHandler::checkCreateAccess()` is running. Looks like `$context['group']` is empty. This is a bug in `group`, because it relies on `$context['group']` being set, which JSON:API and other generic Entity API callers cannot possibly know about. /cc @kristiaanvde

tanasi [11:16 AM]
@e0ipso Yes, those were ommitted too. @wimleers (he/him) thanks for pointing out. I was struggling with that. I hope it will be addressed soon as this is kind of blocking for any Group related decoupled project, right?

e0ipso [11:18 AM]
@tanasi my experience is that _hoping that it will be addressed_ is a risk, as it may not be ever fixed. I'd recommend finding a way to provide a patch or help fund the maintainer to do so.

kristiaanvde [11:18 AM]
This is the first I've heard of this bug, though.

wimleers (he/him) [11:21 AM]
@kristiaanvde It’s really simple though: `\Drupal\group\Entity\Access\GroupContentAccessControlHandler::checkCreateAccess()` requires `$context['group]` to be set, but this is not something any generic module can do.

kristiaanvde [11:22 AM]
Yeah, I'm just trying to figure out where that is usually set

wimleers (he/him) [11:22 AM]
Apparently this was reported 1 year and 5 months ago: https://www.drupal.org/project/group/issues/2942069
Drupal.org
Use jsonapi to post group content article get error
Using jsonpi jsonapi/group_content/business-group_node-article to make a post Header: Authorization:Basic YWRtaW46U3BhcmsxMjMh Content-Type:application/vnd.api+json Accept:application/vnd.api+json Result:
Feb 5th, 2018
@tanasi @kristiaanvde let’s continue in that issue :slightly_smiling_face:
Wim Leers’s picture

Apparently the same issue exists for REST, which is exactly what I would expect: just like JSON:API, rest.module cannot hardcode Group-specific requirements.

Let's continue in #2872645: Creating `Group` content is impossible via REST, JSON:API and GraphQL due to `$context['group']` being required in checking `create` access.