The last remaining deprecation warning in Rules is:

  • 4229x: Constructing a ContextDefinition object for an entity type is deprecated in Drupal 8.6.0. Use Drupal\Core\Plugin\Context\EntityContextDefinition instead. See https://www.drupal.org/node/2976400 for more information.

The Drupal Core issue that is preventing us from fixingConstructing a ContextDefinition object for an entity type is deprecated in Drupal 8.6.0. is #3126747: ContextDefinition::create() can no longer be used with an entitytype-specific datatype (like entity:user) - getting that fixed in core is the last barrier to D9 compatibility.

Details may be found in the parent issue.

Here is a patch that is a pretty terrible solution, but at least it works.

@jonathan1055: Can you check the deprecations with this patch? It fixes them for me ...

Let me repeat, terrible solution, but if it allows us to be D9 compatible then we can add this as a hack to avoid the regression in core while we work on getting core fixed.

Comments

TR created an issue. See original summary.

tr’s picture

Issue summary: View changes
jonathan1055’s picture

StatusFileSize
new5.31 KB

Yes this works on the Travis builds at 8.8 and 8.9 and not a single deprecation message is produced. Here's a patch with adds a drupalci.yml file (not for committing) with suppress-deprecations: false just to prove on d.o. that the messages are not produced.

So how much more testing do we need to do woth this? I will use it for some manual testing, which I presume you have too. If we trust our automated tetss too, then it should be good for committing.

Status: Needs review » Needs work

The last submitted patch, 3: 3161582-3.entity-context-definition.patch, failed testing. View results

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new5.26 KB

OK, so we have one PHPSTAN failure in #3. That implies that phpstan is not run by default on drupal.org, which is useful to know.

file name="core/src/Commands/RulesCommands.php
Class Drush\Commands\DrushCommands not found.

We should look at that separately.

Running again without PHPSTAN

Status: Needs review » Needs work

The last submitted patch, 5: 3161582-5.entity-context-definition.patch, failed testing. View results

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new5.26 KB

OK now for the actual tests

jonathan1055’s picture

That's good. And what's even better is that I have run the tests on Travis at Core 9.0 and everything passes. Needed the obvious changes to composer.json and rules.info.yml plus one change to tests/src/Unit/Integration/RulesEntityIntegrationTestBase.php

--- a/tests/src/Unit/Integration/RulesEntityIntegrationTestBase.php
   protected function setUp() {
     parent::setup();
 
-    require_once $this->root . '/core/includes/entity.inc';
-
     $this->namespaces['Drupal\\Core\\Entity'] = $this->root . '/core/lib/Drupal/Core/Entity';

This looks like legacy code no longer needed, and that file does not exist in D9. The tests also run at 8.8 and 8.9 without that line.

Anyway, that can be dealt with in a separate issue, to get Rules running at D9. For now, this looks OK to be committed. I'm really excited to be getting a D9 version of rules running, thank you TR for doing this work. Even if you say it yourself that it is a bad solution, it keeps us moving forward.

tr’s picture

So how much more testing do we need to do with this? I will use it for some manual testing, which I presume you have too. If we trust our automated tests too, then it should be good for committing.

Well I can say that it's not easy to change ContextDefinition in any way and keep the tests passing - I must have tried a hundred different ways to fix this problem and none of them worked until this one. But yes, I think this can use some manual testing just to ensure that it doesn't affect things we don't explicitly test.

Please open an issue for #8.

The process for rolling out D9 compatibility is:

  1. Fix all deprecations.
  2. Commit a change to core_version_requirements - this has to be done before the testbot can test against D9.
  3. Configure and trigger branch testing for D9.
  4. Fix any test failures caused by API changes in D9 that weren't properly deprecated.

It seems that we'll only have #8 to fix for that last bullet point.

After these steps are taken, we will probably want to make a new release as well.

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

It's not easy to change ContextDefinition in any way and keep the tests passing - I must have tried a hundred different ways to fix this problem and none of them worked until this one.

Yes, you are right. Thanks for your persistence on this. I've been using it today, and, as you say, if the tests pass with this fairly major alteration, and we both agree that manual testing work, I say RTBC.

jonathan1055’s picture

I have opened #3162246: Remove require_once includes/entity.inc which does not exist in D9 for the fix in #8

And that issue shows that this runs OK at D9.0

tr’s picture

I'm going to add a lot comments to this patch then commit it sometime this weekend so we can move forward with D9, as lack of a D9-compatible Rules version is blocking a lot of needed third-party integration.

tr’s picture

StatusFileSize
new7.47 KB
new3.71 KB

Patch with comments added.

  • TR committed 82d91dc on 8.x-3.x
    Issue #3161582 by TR, jonathan1055: EntityContextDefinition breaks the...
tr’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

jonathan1055’s picture

Excellent

Status: Fixed » Closed (fixed)

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