Problem/Motivation

Blocked by #2865616: Add an option for EntityConverter to load the latest entity revision and fix all entity forms to use this option..

We should deprecate the content moderation entity revision converter, it's no longer needed.

Proposed resolution

  • Deprecate the converter.
  • Update it to convert usage of load_pending_revision to load_latest_revision so core understands it.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Sam152 created an issue. See original summary.

sam152’s picture

Title: Remove EntityRevisionConverter from content_moderation. » [PP-1] Remove EntityRevisionConverter from content_moderation.
Issue summary: View changes
plach’s picture

@Sam152 in #2865616-77: Add an option for EntityConverter to load the latest entity revision and fix all entity forms to use this option.:

Paramconverters, access checkers, event subscribers and similar services which are never expected to be used directly either as services or value objects, are not considered part of the API.

Of course we can argue such things in the follow up :)

Well, my goal was reducing disruption (https://www.drupal.org/core/d8-allowed-changes#beta :), given that EntityRevisionConverter is itself an example of a param converter extending another one. OTOH this is not considered a best practice so removing it could be fine:

In general, only interfaces can be relied on as the public API.
With the exception of base classes, developers should generally assume that implementations of classes will change, and that they should not inherit from classes in the system, or be prepared to update code for changes if they do.

sam152’s picture

I don't think removing the class would have been too disruptive, but something I can see that could be is the fact the new converter uses load_latest_revision and CM uses load_pending_revision in the param definition. Lets make EntityRevisionConverter the bridge for these things and deprecate the class and load_pending_revision.

plach’s picture

Yep, that's exactly what I thought, sorry for not being clear.

sam152’s picture

Title: [PP-1] Remove EntityRevisionConverter from content_moderation. » [PP-1] Deprecate EntityRevisionConverter in content_moderation.
Issue summary: View changes

Perfect! Updating IS.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new11.04 KB

Applies on top of the blocker. The deleted test cases all still pass, but given the code they are testing no longer exists, I thought it best to simply remove them.

Status: Needs review » Needs work

The last submitted patch, 7: 2924812-7.patch, failed testing. View results

plach’s picture

It seems #7 is only the actual patch, not the combined one.

plach’s picture

Title: [PP-1] Deprecate EntityRevisionConverter in content_moderation. » Deprecate EntityRevisionConverter in content_moderation.
Status: Needs work » Needs review

The parent issue is in, let's test the patch above again.

Status: Needs review » Needs work

The last submitted patch, 7: 2924812-7.patch, failed testing. View results

sam152’s picture

Hm, these fails don't show up for me locally. I'm using ./core/phpunit.xml.dist too which does contain \Drupal\Tests\Listeners\DeprecationListener, so not sure why it's not showing up.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new768 bytes
new11.2 KB

Status: Needs review » Needs work

The last submitted patch, 13: 2924812-13.patch, failed testing. View results

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new3.95 KB
new12.8 KB

I'm finding it hard to get the deprecations to fail tests locally without altering code in the phpunit-bridge. Not sure what I'm doing wrong there.

As far as the deprecation fails, given the service will be loaded for our BC layer I think the deprecation error needs to be suppressed. To correctly notify users who are in danger of a BC break, we can trigger an error that we don't exclude, only when the load_pending_revision flag is set. This doesn't cover the use case of people extending the class or instantiating the service however, but I think using the flag is going to be a far more common use case. Param converters are not covered in the BC policy, as discussed.

Couldn't really test this patch locally, lets see what the bot says.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me

xjm’s picture

Hm, not sure about adding this message to the suppressed deprecation messages. It makes sense to temporarily suppress the warning for something like drupal_set_message(), but I'm not sure it does for something like this that has low usage. Still trying to follow the implications of #15.

If we do add it to the message list I think there should be an inline comment above it, with the reasoning, and a link to any followup.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2924812-14.patch, failed testing. View results

sam152’s picture

Adding the follow-up issue sounds like a good idea. Here is my understanding of the deprecation fail:

  1. The service is marked as deprecated.
  2. The service is tagged as a param converter, so it's instantiated by ParamConverterManager.
  3. Given the service acts as a BC layer for the load_pending_revision flag, essentially we are deprecating two things at once.
  4. For the BC layer for load_pending_revision to work, the service needs to remain tagged and be used during runtime.
  5. Without the exclusion, all tests that install content_moderation would be marked as failed.
  6. At some point, both the whole service, class and load_pending_revision flag can be removed in one go.

With all that in mind, I think the options are:

  • Remove the deprecation from the param converter class/service, they are internal by definition of the BC policy anyway, hoping nothing depends on it or comes to depend on it in the future. Maybe mark it @internal for good measure.
  • Leave the deprecation and the exclusions, link a follow up that removes them all in one hit.
timmillwood’s picture

I wonder if a "soft" deprecation could be an option. As @Sam152 mentioned, the classes are already marked @internal so we could remove them with no issues? Maybe we could add a message in the comments to say "It's advised to use the "paramconverter.entity" service instead, which now supports loading the latest revision."

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new2.89 KB
new11.3 KB

Implementing @timmillwood's suggestion from #20, I like it!

Remove @deprecated from the class, leaving it as @internal (maybe explicitly mark it as such) and then only trigger the deprecation when people use the flag on routes. Then core and users can fix any routes which use the deprecated feature it offers and anyone instantiating or extending the class directly will get more a more explicit signal that it is internal via a docblock.

wim leers’s picture

  1. +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
    @@ -2,104 +2,28 @@
    + *   load_pending_revision flag. The core entity converter now natively loads
    

    This could mention that load_pending_revision is the predecessor of load_latest_revision

  2. +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
    @@ -2,104 +2,28 @@
    + *   the latest revision of an entity for entity forms and when the
    

    s/and when/when/

  3. +++ b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php
    @@ -2,142 +2,63 @@
    + * @group legacy
    ...
    +   * @expectedDeprecationMessage The load_pending_revision flag has been deprecated. You should use load_latest_revision instead.
    

    👏

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +@deprecated, +Workflow Initiative

Per #2860097-100: Ensure that content translations can be moderated independently.2, this would make that issue slightly simpler.

And actually, I think this patch looks great. #23 are both super nits, really. So … RTBC :)

effulgentsia’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Needs review

This patch looks great to me, and since content_moderation is still an experimental module (until #2897132: Mark Content Moderation module as stable lands), I'm happy to cherry pick this to 8.5.x as well, so setting the Version accordingly.

Just one question about the test coverage:

+++ b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php
@@ -2,142 +2,63 @@
-  public function testConvertNonRevisionableEntityType() {
-  public function testConvertNoEditFormHandler() {

Is there a reason we're removing these tests entirely? Should we instead move them to EntityConverterLatestRevisionTest or elsewhere?

sam152’s picture

StatusFileSize
new3.47 KB
new13.86 KB

Shuffling the comment around a bit to hopefully be clearer.

testConvertNonRevisionableEntityType: while the flag doesn't have any utility when the entity isn't revisionable, as suggested I have added a test to prove nothing blows up when the latest_revision_flag is present.

testConvertNoEditFormHandler: I've added a test case to what I believe is now the responsible party for making this work. When a route exists with _entity_form and no operation (like the original bug report and test case) we are proving the load_latest_revision flag is still added to the route. EntityConverter doesn't use or check this value for anything, so I don't believe we need additional testing beyond this.

plach’s picture

Looks good to me, the only concern I have is that the route defined in EntityResolverManagerTest::testSetLatestRevisionFlag() is /foo/{entity_test} rather than /foo/{entity_test_rev}. Not sure that's relevant.

wim leers’s picture

Is there a reason we're removing these tests entirely?

I asked myself this very question, and first included it in #23. But then I realized that the "edit form" thing was a hardcoded assumption/restriction in the Content Moderation param converter because it was meant to be a param converter used only by/for Content Moderation. Now that that param converter has been generalized into something more broadly useful, there also is no more need for that restriction, because nothing should be using the Content Moderation param converter. Hence also the explicit deprecation error.

The only possible edge case that could regress here is that if you have a route that has an entity edit form, and does not have load_pending_revision set, then this paramconverter would have worked before (applies() would have returned TRUE), and now you'd have to manually set the load_latest_revision flag.

It just seemed so far-fetched that I figured it was safe to go ahead. Now I'd like somebody to explicitly confirm that this edge case is not a problem.

sam152’s picture

I added a test for the flag being added in #26. I don't think the path matters to the test case as per #27 but I would have to check when I'm back at my desk.

effulgentsia’s picture

On quick inspection, #26 looks like adequate test coverage to me, but I haven't yet dug into the background of why these tests were needed to begin with, so I'm not yet 100% clear on whether the new tests address all of the same original concerns. @Sam152, @plach, @Wim Leers, @timmillwood: what do you all think?

timmillwood’s picture

I agree with #30 that the test coverage looks adequate, although it never feels right to delete test.

It also looks like #27 still needs addressing?

sam152’s picture

Re: #27, lets change it to an arbitrary string to prove it doesn't actually have a bearing on the test.

effulgentsia’s picture

Ticking credit boxes for reviewers.

effulgentsia’s picture

StatusFileSize
new13.89 KB

#26 no longer applies. This is just a straight reroll.

  • effulgentsia committed df209e9 on 8.6.x
    Issue #2924812 by Sam152, plach, Wim Leers, timmillwood, xjm: Deprecate...

  • effulgentsia committed bc85165 on 8.5.x
    Issue #2924812 by Sam152, plach, Wim Leers, timmillwood, xjm: Deprecate...
effulgentsia’s picture

Status: Needs review » Fixed
Issue tags: +Needs followup

Given that this was already RTBC in #24, and that more test coverage was added since then, I decided to commit this without awaiting resolution on #32, in order to allow #2860097: Ensure that content translations can be moderated independently to be simplified.

Marking this Fixed, but adding the Needs followup tag for #32. If an additional test is needed, please open a new issue for it. If it turns out not to be needed, please remove the tag.

Thanks!

Status: Fixed » Closed (fixed)

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