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

Created on 31 October 2022, over 2 years ago
Updated 22 February 2023, about 2 years 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 work

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 about 1 year 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.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jan kellermann

    jan kellermann โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany jan kellermann

    I was also not able to reproduce this issue on the 5.x branch when using field_group 3.6 and Drupal 10.3.

    Please give more information to reproduce.

Production build 0.71.5 2024