As per the title, I found these incredibly helpful in the past. If only because of contexts such as;

"liveagent_on" ... test test test blah blah etc etc

And then ...

"liveagent_off" using config;

~liveagent_on

Cos well ... it'll only ever be one or the other.

Issue fork context-2948830

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

pobster created an issue. See original summary.

pobster’s picture

So I gave it a go ... but TBH ... it doesn't work properly due to "Fatal error: Maximum execution time of 30 seconds exceeded..." but I feel though it's a good start? I was hoping for a pointer or two and I'll (or anyone) can finish it off (and the "Context (all)" will be similar enough I'm sure).

perke’s picture

Would love to see this moving forward.... can't provide code but will happily test and provide feedback

Kaz de Groot’s picture

This probably requires some changes in the main context system, as this patch currently creates an infinite loop.

Basically, on evaluate, activeContexts is fired, which runs evaluate for all conditions on all contexts, and thus will fire the evaluate on the Context (any) condition, which will then fire activeContexts, etc.

Based on the description, some technique should be employed that would only run the Context (all) check after all the other conditions have fired; but I don't think there is mechanism for that currently. Another way would be to duplicate the context triggering logic within the plugin, but that would be hard to maintain.

etroid’s picture

A first stab at making this work. Similarly to the D7 version, we'll have to evaluate the contexts directly as they are being referenced in the `context_any` plugin.

etroid’s picture

StatusFileSize
new6.37 KB
etroid’s picture

StatusFileSize
new1.64 KB

Fixed some code style issues

etroid’s picture

StatusFileSize
new6.31 KB
etroid’s picture

Also include context (all) condition plugin this time.

etroid’s picture

etroid’s picture

StatusFileSize
new10.96 KB

Fixed an issue with duplicate plugin id

etroid’s picture

StatusFileSize
new12.42 KB

Included cache context support.

etroid’s picture

Status: Needs work » Needs review
etroid’s picture

StatusFileSize
new12.58 KB

Fixed an issue around negated contexts. These conditions probably need some testing

strozx’s picture

Status: Needs review » Reviewed & tested by the community

I tested with different conditions and reactions and it look like it works

ilgnerfagundes’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new74.47 KB

Hi guys, I was unable to apply the patch. You may have to update

paulocs’s picture

Status: Needs review » Needs work

Patch needs re-roll

deaom’s picture

I re-rolled the patch, but the asterisk (*) is not working (fatal error is thrown because null is returned), so I'm currently debugging why as it seems this was also not working in the D7 version.

deaom’s picture

Status: Needs work » Needs review

I created a new fork as it's more manageable and pushed the re-rolled patch with the asterisks/wildcard handling. Needs additional testing.
If necessary I can also upload the .patch file. Setting to needs review.

paulocs’s picture

Status: Needs review » Needs work

Hi @DeaOm,
I was testing it and I found a bug.
Steps to reproduce:
1) Create a context that will add a block if the current page is the front page.
2) Create a second context with "Context (any)" condition, add the context created in step 1 and add a page title reaction.
3) Save it and see the error below:

Warning: Undefined array key "" in Drupal\context\ContextManager->getContext() (line 169 of modules/contrib/context/src/ContextManager.php).
Warning: foreach() argument must be of type array|object, null given in Drupal\context\Plugin\Condition\ContextAny->evaluate() (line 164 of modules/contrib/context/src/Plugin/Condition/ContextAny.php).
deaom’s picture

Status: Needs work » Needs review

Hi @paulocs, I could reproduce your bug. I pushed changes for that bug/issue to the MR, so setting status to needs review.

paulocs’s picture

Status: Needs review » Needs work

I found another error when adding a context id that does not exist.
The site totally crashes if I write a wrong context id and I'm not even able to edit the context and fix it.

I tested it with Context (any).

deaom’s picture

Status: Needs work » Needs review

Added the updated code to context any and all condition. Not sure how to actually handle the wrong name, as the code will work, but the user will have no idea that the entered context name is wrong. Here is kinda assumed you know what you are doing, so the complete crash of the page of course is not correct, but maybe some kind of a warning could be displayed? For when user mistypes or something. Setting it to needs review and we'll see from there.

larisse’s picture

Status: Needs review » Reviewed & tested by the community

I tested and the re-rrol works. But when I adding a context that not exist, it's save normally. I tested in Drupal 7 to see how this case works there and I see that when adding a context that not exists, it's save normally too.

paulocs’s picture

Thanks!
It looks good to me as well.
I'll commit and add it to the next release.

  • paulocs committed 89d35ab on 8.x-4.x authored by DeaOm
    Issue #2948830 by Etroid, DeaOm, pobster, ilgnerfagundes, paulocs, perke...
paulocs’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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