Reviewed & tested by the community
Project:
Context
Version:
5.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Feb 2022 at 05:09 UTC
Updated:
6 Jun 2025 at 06:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
loze commentedComment #3
loze commentedI combed through the code and couldn't find a way to do this. so I added a method to the contextManager.
It appears to work as expected. Now if I call the following:
\Drupal::service('context.manager')->setActiveContext('CONTEXT_NAME');from my custom module, the context is set (provided it exists and is enabled)
Comment #4
loze commentedComment #5
loze commentedComment #7
loze commentedChanged setActiveContext($name) to setActiveContexts($context_names);
Added unsetActiveContexts($context_names);
Added isActiveContext($name);
Comment #8
loze commentedComment #9
admirlju commentedThe changes worked for me. I'm just wondering if maybe there should be some tests made for this code because it's not used by any other code and someone might potentially delete it in the future. So I'll leave it as Needs Review for now, just so people can debate this a bit.
Comment #11
markman4897 commentedI have submitted a commit that removes an unnecessary newline in the ContextManager.php file.
Additionally, I have written basic kernel tests to validate the new functionality implemented in this issue.
Comment #12
loze commentedThanks for the test @agile-mark-l this looks good.
Comment #13
Anonymous (not verified) commentedI've taken a look into this feature requests and it seems that MR is ready to be merged, tests pass and feature has been implemented as requested. Marking this issue as RTBC.