Problem/Motivation

When we use field_permissions_group, we get an exception when creating a group (see backtrace below).

The root reason is GroupContentStorage::loadByGroup() which throws on an unsaved Group, but its PHPDoc contract does not announce a @throws.

Major as of WSOD.

Backtrace of field_permissions_group check
Drupal\Core\Entity\EntityStorageException: Cannot load GroupContent entities for an unsaved group. in Drupal\group\Entity\Storage\GroupContentStorage->loadByGroup() (line 71 of modules/contrib/group/src/Entity/Storage/GroupContentStorage.php).

Drupal\group\GroupMembershipLoader->load(Object, Object) (Line: 190)
Drupal\group\Entity\Group->getMember(Object) (Line: 73)
Drupal\field_permissions_group\Plugin\FieldPermissionType\CustomGroupAccess->hasFieldAccess('edit', Object, Object) (Line: 174)
Drupal\field_permissions\FieldPermissionsService->getFieldAccess('edit', Object, Object, Object) (Line: 39)
field_permissions_entity_field_access('edit', Object, Object, Object)
call_user_func_array('field_permissions_entity_field_access', Array) (Line: 392)
Drupal\Core\Extension\ModuleHandler->invoke('field_permissions', 'entity_field_access', Array) (Line: 347)
Drupal\Core\Entity\EntityAccessControlHandler->fieldAccess('edit', Object, Object, Object, ) (Line: 154)
Drupal\Core\Field\FieldItemList->access('edit') (Line: 179)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 125)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 149)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('group_mitgliedschaft_add_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 61)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'add', Array) (Line: 124)
Drupal\group\Entity\Controller\GroupController->addForm(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

See above.

Proposed resolution

Make GroupContentStorage::loadByGroup adhere to the contract and return an empty array.

Remaining tasks

Patch, check, commit.

User interface changes

None.

API changes

The code will do what the API says.

Data model changes

None.

Issue fork group-3179857

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Status: Active » Needs review

That should fix it.

geek-merlin’s picture

Status: Needs review » Needs work

OK so while not documented this behavior has test coverage. So maybe we have to go the other way and document it.
In that case the above WSOD has to be fixed in the other module.

dropa’s picture

Category: Bug report » Feature request
Priority: Major » Normal
Status: Needs work » Closed (duplicate)

Firstly, not a major. The WSOD in your example is created by your custom code, not by Group module. Also because of that, it is not bug either.

Secondly, you added this as "related" bug in #3040478 while this is simple duplicate of that, so that is not related to this, and this is not related to that. Related is not synonym for duplicate.

Thirdly, you're allowed to add patches to issues opened by others too.

elwerene’s picture

I created an issue at the field_permission_group module to address the reason why we ran into this issue: https://www.drupal.org/project/field_permissions_group/issues/3181785