Problem/Motivation

When accessing the path group_hierarchy route (path: /admin/group/group-hierarchy) the following fatal error is hit:

TypeError: Drupal\group_hierarchy\Controller\GroupHierarchyController::buildTree(): Argument #2 ($group_hierarchy) must be of type array, null given, called in /var/www/html/web/modules/contrib/group_hierarchy/src/Controller/GroupHierarchyController.php on line 119 in Drupal\group_hierarchy\Controller\GroupHierarchyController->buildTree() (line 191 of /var/www/html/web/modules/contrib/group_hierarchy/src/Controller/GroupHierarchyController.php)

#0 /var/www/html/web/modules/contrib/group_hierarchy/src/Controller/GroupHierarchyController.php(119): Drupal\group_hierarchy\Controller\GroupHierarchyController->buildTree(Array, NULL)
#1 [internal function]: Drupal\group_hierarchy\Controller\GroupHierarchyController->build()
#2 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#3 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#4 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#5 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#6 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#7 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#8 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#9 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#10 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#11 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#17 {main}

Steps to reproduce

  1. Enable the module
  2. Create two groups
  3. Create a hierarchy
  4. Access the given route
  5. Observe bug
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

    Jaypan created an issue. See original summary.

    jaypan’s picture

    akram khan’s picture

    Status: Active » Needs review
    StatusFileSize
    new739.4 KB
    new238.95 KB

    I reviewed the patch and it's resolved the issue. Before patch when i try to access the (path: /admin/group/group-hierarchy) it gives TypeError and after applying patch the page appear successfully. Additionally, I have attached before and after state screenshots for reference.

    jay jangid’s picture

    Assigned: Unassigned » jay jangid
    jay jangid’s picture

    Assigned: jay jangid » Unassigned
    StatusFileSize
    new58.75 KB
    new44.08 KB

    I have reviewed and implemented the Patch provided by @Jaypan.
    The Patch has been applied successfully on Drupal 9.5.x.
    Now errors are removed which is shown before applying the patch.
    I am sharing screenshots for your reference.
    Please review.
    Thank You.

    jaypan’s picture

    Status: Needs review » Reviewed & tested by the community
    jdleonard’s picture

    Patch appears to work for me on Drupal 10.1.1. Thanks!

    • facine committed f0e0093d on 1.x
      Issue #3374016 by jaypan, jay jangid, akram khan, jdleonard: Error when...
    facine’s picture

    Status: Reviewed & tested by the community » Fixed

    Fixed, thanks!

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.