Establish compatibility with group 3.x

Created on 3 October 2023, 9 months ago
Updated 29 April 2024, about 2 months ago

There have been some small re-namings in group module from version 2 to 3.
Of course this results in a couple of issues when trying to use this module with the newest group version.

Problem/Motivation

Can't edit fields with this module enabled.

Steps to reproduce

When trying to edit any field, I've got the following error:

Fatal error: Declaration of Drupal\field_permissions_group\Plugin\FieldPermissionType\CustomGroupAccess::create(Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?Drupal\field\FieldConfigInterface $field_config = null) must be compatible with Drupal\field_permissions\Plugin\FieldPermissionType\Base::create(Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?Drupal\field\FieldStorageConfigInterface $field_storage = null) in /var/www/html/web/modules/contrib/field_permissions_group/src/Plugin/FieldPermissionType/CustomGroupAccess.php on line 70
Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom kenorb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kenorb
  • 🇬🇧United Kingdom kenorb
  • 🇩🇪Germany Istari

    Anything new with this error?
    I'm facing the same issue.

  • 🇩🇪Germany Istari

    I did a little research within the code and found out, that the function CustomGroupAccess::create( ) needs the argument FieldStorageConfigInterface $field_storage, based on the Base class (Base.php) which it is inherited from.

    So before:

      public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, FieldConfigInterface $field_config = NULL) {
        return new static(
          $configuration,
          $plugin_id,
          $plugin_definition,
          $field_config,
          $container->get('field_permissions.permissions_service'),
          $container->get('plugin.manager.group_content_enabler')
        );
      }

    And after the changes:

      public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, FieldStorageConfigInterface $field_storage = NULL) {
        return new static(
          $configuration,
          $plugin_id,
          $plugin_definition, 
          $field_storage ,
          $container->get('field_permissions.permissions_service'),
          $container->get('plugin.manager.group_content_enabler')
        );
      }

    Changing this comes with a new follow up error that says:

    Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "plugin.manager.group_content_enabler". in Drupal\Component\DependencyInjection\Container->get() (line 157 of core/lib/Drupal/Component/DependencyInjection/Container.php).

    So taking a look into the field_permissions_group.service.yml, field_permissions_group.services.yml, and group.services.yml neither shows a similar defined service or with similar logic.

    I'd like to fix this issue, but my knowledge is far beyond of the understanding of this, cause I'm pretty new to Drupal.
    But maybe this is a help for someone more experienced like me who may fixing it or giving a hint into the right direction :P

    I hope it helps :)

  • First commit to issue fork.
  • I write patch for this module. This patch fix problem for new group version

  • Status changed to Needs review 7 months ago
  • 🇮🇳India abhishek_virasat

    @kenorb, I have fix the issue pls kindly review the MR

  • 🇩🇪Germany Hydra

    I adjusted the issue metadata, because it's about making this module compatible with the 3.x version of group. The maintainers need to make sure that a new version of this module is tagged and the module page gives information about that.

  • 🇩🇪Germany Istari

    I have tested the patch and it comes to a thrown error:

    Error: Call to a member function getName() on null in Drupal\field_permissions_group\Plugin\FieldPermissionType\CustomGroupAccess->hasFieldAccess() (line 95 of modules/contrib/field_permissions_group/src/Plugin/FieldPermissionType/CustomGroupAccess.php).
    Drupal\field_permissions\FieldPermissionsService->getFieldAccess('view', Object, Object, Object) (Line: 39)
    field_permissions_entity_field_access('view', Object, Object, Object) (Line: 350)
    Drupal\Core\Entity\EntityAccessControlHandler->Drupal\Core\Entity\{closure}(Object, 'field_permissions') (Line: 388)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_field_access', Object) (Line: 351)
    Drupal\Core\Entity\EntityAccessControlHandler->fieldAccess('view', Object, Object, Object, 1) (Line: 154)
    Drupal\Core\Field\FieldItemList->access('view', NULL, 1) (Line: 253)
    Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 268)
    Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 339)
    Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 281)
    Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 238)
    Drupal\Core\Entity\EntityViewBuilder->build(Array)
    call_user_func_array(Array, Array) (Line: 111)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 797)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 386)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    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: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    Steps to reproduce
    - Create group
    - Create insider and outsider role
    - Make sure to have admin access to group
    - Create two testing field types (A and B)
    - assign view access to insider for field type A
    - assign no access to insider for field type B
    - open group page (/group/id)

  • First commit to issue fork.
  • 🇩🇪Germany Hydra

    @Islanderweedy I don't think it's a good idea to commit this to the 1.0.x branch. There are still a lot of people out there using group 1, which got extended support for D10.
    This would break all those group1 sites using your module.

  • 🇺🇦Ukraine alt.dev

    When I apply this patch and try to add fields to the group content, I receive the next error:

    Drupal\Core\Entity\EntityStorageException: 'group_relationship_type' entity with ID 'community-group_node-record' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 519 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

    Attaching an updated patch that solves this issue.

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    geek-merlin changed the visibility of the branch 3391457-fatal-error-when to hidden.

  • 🇺🇸United States pdcarto

    The updated patch works for me - fixes this issue with group v2.2.2

Production build 0.69.0 2024