Call to a member function id() on string in Drupal\context\ContextManager->getContext()

Created on 31 October 2022, about 2 years ago
Updated 16 September 2024, 2 months ago

Problem/Motivation

I am getting the following error then trying to add a field group in a user form (page: /admin/config/people/accounts/form-display/add-group)

Error: Call to a member function id() on string in Drupal\context\ContextManager->getContext() (line 157 of modules/contrib/context/src/ContextManager.php).

The getContext() method calls $this->currentRouteMatch->getParameter('context')->id()
in the case of this page currentRouteMatch->getParameter('context') is the string "form"

Proposed resolution

getContext() should check that the route parameter is a context entity instance before trying to get the id.

🐛 Bug report
Status

Needs review

Version

5.0

Component

Code

Created by

🇺🇸United States loze Los Angeles

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States Kristen Pol Santa Cruz, CA, USA

    Thanks for the patch. It would be good to get more explicit steps to reproduce so tagging. Switching this to the 5.x branch as that is the latest release though it can be back ported.

    +++ b/src/ContextManager.php	(revision 2d10edc91d2739a3ee0db246fb5c18127a043a9c)
    @@ -151,7 +151,9 @@
    -    $currentContext = $this->currentRouteMatch->getParameter('context') ? $this->currentRouteMatch->getParameter('context')->id() : '';
    +    $currentContext = $this->currentRouteMatch->getParameter('context');
    +    $currentContext = ($currentContext instanceof Context) ? $currentContext->id() : '';
    +    ¶
    

    Extraneous spaces on empty line.

  • Status changed to Needs review 9 months ago
  • 🇮🇳India chaitanyadessai Goa

    Addressed #8 please review.

  • 🇮🇳India Jasjeet Kaur Brar

    Pardon me, but I am on branch 5.x but when I visit the path to add a field-group, I am getting permission errors.
    Please assist me in reproducing this on 5.x so that i can apply patches in it.
    Please & Thank You.

  • 🇸🇮Slovenia agile-mark-l

    I was not able to reproduce this issue on the 5.x branch when using field_group module version 3.6.0 and Drupal version 9.5.11.

Production build 0.71.5 2024